【发布时间】:2014-05-08 15:37:57
【问题描述】:
我正在创建一个有暂停按钮的游戏。为了检查它是否被触摸,我正在检查触摸的位置以及它是否等于暂停的按钮名称。
当点击 pausedButton 时,它会调用一个暂停场景的方法。
问题在于,在 touchBegan 方法中,每当您触摸屏幕时,它都会施加一个脉冲,因此当我按下 pauseButton 并取消暂停时,applyforce 会随之而来。这对于游戏来说并不理想。我已经尝试过像 shouldImpulse 这样的布尔值,但还没有让它工作。这是我的touchBegan方法:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
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 (started == 1) {
mover.physicsBody.restitution = 0.0;
mover.physicsBody.velocity = CGVectorMake(0, 0);
[mover.physicsBody applyImpulse:CGVectorMake(0, 15)];
}
}
【问题讨论】:
-
不要创建重复的问题。如果您需要更改您的问题,请编辑它。
标签: ios objective-c sprite-kit