我正在制作一个游戏,您应该在其他图像之间移动图像而不会发生碰撞。一切正常,直到我在游戏中添加硬币。当图像击中硬币时,它应该发出声音(它会发出声音)并向硬币标签添加+1。问题是,当我添加代码以使coinlabel获得+1时,我正在移动的图像将停止并返回到起始位置。当我使用NSTimer
时,同样的事情发生在我身上(因为玩这个应用程序的用户有时间完成关卡。)但每次标签计算一个数字时,游戏再次停止并且球被放回到起始位置。
这是游戏的一些代码。
-(IBAction)left {
goLeft = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goLeft) userInfo:nil repeats:YES];
if (goLeft == nil) {
goLeft = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goLeft) userInfo:nil repeats:YES];
}
}
-(IBAction)stopLeft {
[goLeft invalidate]; goLeft = nil;
}
-(void)goLeft {
image.center = CGPointMake(image.center.x -3.5, image.center.y);
{
//Coins
if (CGRectIntersectsRect(image.frame, coin1.frame)) {
coin1.hidden = YES;
[self getcoins];
}
-(void)getcoins{
//Here i have a avaudioplayer playing a noise (dont need to show that as that works fine)
//Then the +1 to label
coinlabel.text = [[NSNumber numberWithInt:([coinlabel.text intValue] + 1)] stringValue];
// And when i add this and the image hits the coin, the image goes back to the starting position. But i want it not to stop or anything, but continue.
}
左侧动作连接到触地。并且stopleft连接到内部触摸。希望您理解并感谢您的帮助。