Alright so I am just starting out with programming and I have been following the tutorials in the book called beginning iphone games development. I am on the first tutorial which is making a brick breaker game. However when I build and run I get 4 errors and warnings in my viewcontroller.m file. The errors are 'expected declaration or statement at end of input' and 'view did load undeclared'.
Here is my header:
And here is my main
Thanks for any help.
Here is my header:
Code:
#import <UIKit/UIKit.h>
@interface Ball_Game_2ViewController : UIViewController {
UILabel *scoreLabel;
int score;
UIImageView *ball;
CGPoint ballMovement;
UIImageView *paddle;
float touchOffset;
}
@property (nonatomic, retain) IBOutlet UILabel *scoreLabel;
@property (nonatomic, retain) IBOutlet UIImageView *ball;
@property (nonatomic, retain) IBOutlet UIImageView *paddle;
- (void)initializeTimer;
- (void)animateBall:(NSTimer *)theTimer;
@end
And here is my main
Code:
#import "Ball_Game_2ViewController.h"
@implementation Ball_Game_2ViewController
@synthesize scoreLabel;
@synthesize ball;
@synthesize paddle;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
touchOffset = paddle.center.x -
[touch locationInView:touch.view].x;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
float distanceMoved = }
([touch locationInView:touch.view].x + touchOffset) -
paddle.center.x;
float newX = paddle.center.x + distanceMoved;
if (newX > 30 && newX < 290)
paddle.center = CGPointMake( newX, paddle.center.y );
if (newX > 290)
paddle.center = CGPointMake( 290, paddle.center.y );
if (newX < 30)
paddle.center = CGPointMake( 30, paddle.center.y );
- (void)viewDidLoad {
[super viewDidLoad];
ballMovement = CGPointMake(4,4);
[self initializeTimer];
}
{- (void)initializeTimer
float theInterval = 1.0/30.0;
[NSTimer scheduledTimerWithTimeInterval:theInterval target:self
selector:@selector(animateBall:) userInfo:nil repeats:YES];
}
- (void)animateBall:(NSTimer *)theTimer {
ball.center = CGPointMake(ball.center.x+ballMovement.x,
ball.center.y+ballMovement.y);
if(ball.center.x > 300 || ball.center.x < 20)
ballMovement.x = -ballMovement.x;
if(ball.center.y > 440 || ball.center.y < 40)
ballMovement.y = -ballMovement.y;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[scoreLabel release];
[ball release]
[paddle release]
[super dealloc];
}
@end
Thanks for any help.