我的代码:
-(SKSpriteNode*) pauseButton
{
SKSpriteNode* pauseButton = [SKSpriteNode spriteNodeWithImageNamed:@"pausebutton"];
pauseButton.position = CGPointMake(CGRectGetMaxX(self.frame) -30,CGRectGetMaxY(self.frame) - 30);
pauseButton.anchorPoint = CGPointMake(1.0, 1.0);
pauseButton.name = @"pauseButton";
pauseButton.zPosition = 160;
return pauseButton;
}
-(SKSpriteNode*) playButton
{
SKSpriteNode* playButton = [SKSpriteNode spriteNodeWithImageNamed:@"playbutton"];
playButton.position = CGPointMake(CGRectGetMaxX(self.frame)- 30, CGRectGetMaxY(self.frame) - 30);
playButton.anchorPoint = CGPointMake(1.0, 1.0);
playButton.name = @"playButton";
playButton.zPosition = -10;
return playButton;
}
在touchesBegan:
SKSpriteNode *pauseButton = (SKSpriteNode*)[self childNodeWithName:@"pauseButton"];
CGPoint location = [touch locationInNode:self];
if (!(gameIsOver))
{
if([pauseButton containsPoint:location])
{
if (self.scene.view.paused==YES)
{
[myTimer start];
pauseButton.zPosition = 160;
[self childNodeWithName:@"playButton"].zPosition = -10;
self.scene.view.paused = NO;
}
else if (self.scene.view.paused ==NO)
{
pauseButton.zPosition = -10;
[self childNodeWithName:@"playButton"].zPosition = 160;
[myTimer pause];
[self performSelector:@selector(pauseGame) withObject:Nil afterDelay:0.01];
}
}
-(void) pauseGame
{
self.scene.view.paused = YES;
}
我的问题:
我不想使用:[self performSelector:@selector(pauseGame) withObject:Nil afterDelay:0.01];
因为它不准确。我想在有人点击暂停按钮后立即设置self.scene.view.paused = YES;
。但是,不设置延迟不会让暂停按钮改变播放。有没有办法解决这个问题。
有时,我的暂停按钮不会改变播放。我不知道为什么。这很少见。
任何帮助都将不胜感激。
由于