I am new in the game, so this is probably a stupid question, but I am experiencing a great deal of trouble over this code I am working on. I am trying to make the ball go to the right when you press the right side of the screen, and vise versa for the left, but thus far it crashes when I touch the screen 🙁
Any suggestions? Thanks a lot!
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:touch.view];
if (gameState == kStateRunning && controlType == kTouch) {
if (location.x < (self.view.bounds.size.width/2)) {
touchState = kLeftDown;
ballVelocity.x -= 0.2;
}
else {
touchState = kRightDown;
ballVelocity.x += 0.2;
}
}
if (gameState == kStateGameOver) {
if (location.x < (self.view.bounds.size.width/2)) {
gameState = kStateMenu;
}
else {
gameState = kStateRunning;
}
Nothing obviously wrong there that I can see (assuming you have defined all your constants, etc.)
Having been bitten by it a few times, the first thing I check now with odd crashes is if there are any broken IBOutlet or IBAction links on the viewController owner (indicated by those orange alert triangles).
I guess then I would comment out everything within that function and see if it still crashes. Then NSLog statements, etc – standard debugging.