在我的第一个场景中,我有CGVector
值,使球在屏幕上反弹。当加载回这个屏幕时(从屏幕上的游戏中),该值已经改变,使得球的移动速度比我想要的慢得多。
第一个场景addBall
方法:
CGVector ballDirection = CGVectorMake (40,120);
[ball.physicsBody applyForce:ballDirection];
从游戏场景回到第一个场景:
-(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];
}
不确定为什么CGVectorMake
值似乎已更改,因为addBall
方法在转换回第一个场景时会在initWithSize
中调用。
我尝试了以下但没有成功:
static CGFloat dx = 40;
static CGFloat dy = 120;
CGVector ballDirection = CGVectorMake(dx, dy);
[ball.physicsBody applyForce:ballDirection];