[英]Making a method so as to be able to move the ball in PapiJump sideways by touching the sides of the screen
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). 被它咬了几次之后,我现在首先检查的是奇怪的崩溃情况:viewController所有者上是否存在任何损坏的IBOutlet或IBAction链接(由那些橙色的警告三角形表示)。
I guess then I would comment out everything within that function and see if it still crashes. 我猜想我会注释掉该函数中的所有内容,看看它是否仍然崩溃。 Then NSLog statements, etc - standard debugging.
然后是NSLog语句,等等-标准调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.