2014-05-06 5 views
1

Я пытаюсь создать кнопку паузы в своей игре. в тот момент, когда вы нажмете на экран, он применит импульс к движку spriteNode. Проблема в том, что он все еще применяет импульс, когда я нажимаю кнопку паузы. Как я могу создать кнопку паузы, не создавая импульс.stop impulse on SKSpriteKit click

Я попытался изменить инструкции if на другое, если и затем сделать последнюю часть импульса частью else, но это не будет работать. Метод

touchBegan:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    CGPoint location = [touch locationInNode:self]; 
    SKNode *node = [self nodeAtPoint:location]; 

    //if fire button touched, bring the rain 
    if ([node.name isEqualToString:@"repeat"]) { 
     SKTransition *reveal = [SKTransition fadeWithDuration:2.0 ]; 
     MyScene *newScene = [[MyScene alloc] initWithSize: CGSizeMake(self.size.width,self.size.height)]; 
     // Optionally, insert code to configure the new scene. 
     [self.scene.view presentScene: newScene transition: reveal]; 
    } 

    if ([node.name isEqualToString:@"home"]) { 
     SKTransition *reveal = [SKTransition fadeWithDuration:2.0 ]; 
     Menu *newScene = [[Menu alloc] initWithSize: CGSizeMake(self.size.width,self.size.height)]; 
     // Optionally, insert code to configure the new scene. 
     [self.scene.view presentScene: newScene transition: reveal]; 
    } 

    if ([node.name isEqualToString:@"pause"]) { 
     [self pausedMenu]; 
    } 

    if ([node.name isEqualToString:@"start"]) { 
     [self startMenu]; 
    } 

    showpipes = showpipes + 1; 

    if (showpipes == 1) { 
     self.physicsWorld.gravity = CGVectorMake(0.0, -5.0); 

     SKAction* spawn = [SKAction performSelector:@selector(spawnPipes) onTarget:self]; 
     SKAction* delay = [SKAction waitForDuration:2.0]; 
     SKAction* spawnThenDelay = [SKAction sequence:@[spawn, delay]]; 
     SKAction* spawnThenDelayForever = [SKAction repeatActionForever:spawnThenDelay]; 
     [self runAction:spawnThenDelayForever]; 
    } 

    started = 1; 

    if (noImpulse == 1) { 
     if (started == 1) { 
      mover.physicsBody.restitution = 0.0; 
      mover.physicsBody.velocity = CGVectorMake(0, 0); 
      [mover.physicsBody applyImpulse:CGVectorMake(0, 15)]; 
     } 
    } 

} 

PAUSEDMENU МЕТОД:

-(void)pausedMenu 
{ 

self.scene.paused = YES; 
mover.scene.paused = YES; 
[repeatButton removeFromParent]; 
[homeButton removeFromParent]; 
[menuBackground removeFromParent]; 
menuBackground = [SKSpriteNode spriteNodeWithColor:[SKColor colorWithWhite:0.0 alpha:0.3] size:CGSizeMake(self.frame.size.width*2, self.frame.size.height*2)]; 


[self addChild:menuBackground]; 

[pauseButton removeFromParent]; 

startButton = [SKSpriteNode spriteNodeWithImageNamed:@"staart"]; 
startButton.name = @"start"; 
startButton.position = CGPointMake(20, self.size.height-20); 
startButton.size = CGSizeMake(40, 40); 
[self addChild:startButton]; 



repeatButton = [SKSpriteNode spriteNodeWithImageNamed:@"repeat"]; 
repeatButton.name = @"repeat"; 
repeatButton.position = CGPointMake(self.size.width/2+30, self.size.height/2); 
repeatButton.size = CGSizeMake(repeatButton.size.width/2, repeatButton.size.height/2); 
[self addChild:repeatButton]; 

homeButton = [SKSpriteNode spriteNodeWithImageNamed:@"home"]; 
homeButton.name = @"home"; 
homeButton.position = CGPointMake(self.size.width/2-30, self.size.height/2); 
homeButton.size = CGSizeMake(homeButton.size.width/2, homeButton.size.height/2); 
[self addChild:homeButton]; 

} 
+0

Является ли узел «паузой» логической кнопки паузы? – ColdLogic

+0

да, это логика паузы. поэтому, когда я нажимаю кнопку паузы, он будет запускать этот код. но он все равно будет управлять импульсом. который он не должен – user3423384

+0

Итак, вы не хотите, чтобы что-то еще произошло, кроме '[self pausedMenu]', когда вы нажимаете паузу, правильно? – ColdLogic

ответ

3

Заканчивать https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKView/Reference/Reference.html#//apple_ref/occ/instp/SKView/paused Если вы приостановите SKView, который содержит игру, все государство будет действительно паузе, и вы будете может возобновить его после того, как меню паузы было уволено. Вам нужно будет представить меню паузы в другом SKView, а затем в том, что содержится в вашей игре.