如何在移动的 UIImage 到达特定点后执行操作
我正在尝试一款乒乓球游戏,以开始在 iPhone 上开发游戏,我已经完成了所有操作,但我需要实现得分并使球返回屏幕中心 这是我目前在 TouchesBegan 方法中的代码:
if(ball.center.y >=444) {
computerScore=computerScore+1;
computerScoreLabel=[NSString stringWithFormat:@"%d", computer];
ball.center.x=151;
ball.center.y=222;
}
if(ball.center.y <=4) {
playerScore=playerScore+1;
playerScoreLabel=[NSString stringWithFormat:@"%d", player];
ball.center.x=151;
ball.center.y=222;
}
它正确构建并运行,但是当我在模拟器上尝试游戏时,它只会使球移动,当它通过特定点时,它只会弹开,并且得分不会改变
i am trying out a pong game to start out developing games on the the iphone and i've got everything moving but i need to implement the scoring and make the ball return to the center of the screen
this is the code i have currently in the touchesBegan method:
if(ball.center.y >=444) {
computerScore=computerScore+1;
computerScoreLabel=[NSString stringWithFormat:@"%d", computer];
ball.center.x=151;
ball.center.y=222;
}
if(ball.center.y <=4) {
playerScore=playerScore+1;
playerScoreLabel=[NSString stringWithFormat:@"%d", player];
ball.center.x=151;
ball.center.y=222;
}
it builds correctly and runs, but when i try the game on the simulator it just makes the ball move around and when it passes the specific points it just bounces off and the score doesn't change
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您添加一个 NSLog() 语句,以便您可以实际监视 ball.center.y 的值,并查看它是否在该值实际与您的条件匹配之前触发碰撞反弹。
I suggest you add an NSLog() statement so you can actually monitor the value of ball.center.y and see if it's, for instance, triggering a collision-bounce before the value actually matches your conditional.