my problem is that when i jump at the start of my game it jumps three times when I only want to jump 2 times. What the code does is at the start a bool startgame is set to false and when clicked start moving the shape and starts the animation of dan, the character of my game. In the update method whenever the shape and dan touch the isjumping boolean variable is set to false so that when you click, dan jumps and then sets the didjumponce boolean to true so that it can jump for a second time. but for some reason at the start of the game it allows dan to jump three times. i tried setting a touch counter(timestapped) to 0 and every time there is a tap it adds on 1 so that when it checks if you can jump a second time is doesn't allow it. but it still does. thanks :)
@implementation GameScene
bool isJumping;
bool isPlaying;
bool didJumpOnce;
bool startGame = false;
int timesTapped = 0;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
/* Called when a touch begins */
timesTapped++;
// checks to see if the game has started, if it hasn't, starts dan's animation
if (startGame == false)
{
startGame = true;
[self dansAnimation];
}
else if (isJumping == false)
{
isJumping = true;
didJumpOnce = true;
dan.physicsBody.velocity = CGVectorMake(0, 0);
[dan.physicsBody applyImpulse: CGVectorMake(0, 55)];
}
else if (didJumpOnce == true && timesTapped != 2)
{
didJumpOnce = false;
dan.physicsBody.velocity = CGVectorMake(0, 0);
[dan.physicsBody applyImpulse: CGVectorMake(0, 55)];
}
}
-(void)update:(CFTimeInterval)currentTime
{
/* Called before each frame is rendered */
if (startGame == true)
{
shape.position = CGPointMake(shape.position.x - 7, shape.position.y);
}
if (CGRectIntersectsRect(dan.frame, shape.frame))
{
isJumping = false;
}
}
@end
Aucun commentaire:
Enregistrer un commentaire