In my first scene I have a CGVector
value that makes a ball bounce around the screen. When loading back to this screen (from a game over screen), the value has changed making the ball move much slower than I want.
First scene addBall
method:
CGVector ballDirection = CGVectorMake (40,120);
[ball.physicsBody applyForce:ballDirection];
Moving back to the first scene from game over scene:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
MyScene *firstScene = [MyScene sceneWithSize:self.size];
[self.view presentScene:firstScene transition:[SKTransition doorsOpenHorizontalWithDuration:0.5]];
SKAction *playAgainSound = [SKAction playSoundFileNamed:@"opening.wav" waitForCompletion:NO];
[self.scene runAction:playAgainSound];
}
Not sure why the CGVectorMake
value appears to have changed as the addBall
method will get called in initWithSize
when transitioning back to the first scene.
I tried the following without success:
static CGFloat dx = 40;
static CGFloat dy = 120;
CGVector ballDirection = CGVectorMake(dx, dy);
[ball.physicsBody applyForce:ballDirection];