我是游戏新手,所以这可能是一个愚蠢的问题,但是我正在处理的这段代码遇到了很多麻烦。当您按下屏幕的右侧时,我试图让球向右移动,左侧反之亦然,但到目前为止,当我触摸屏幕时它会崩溃:-(
有什么建议么?非常感谢!
-(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;
}