SpriteKit重力加速度

时间:2014-04-10 16:16:11

标签: ios ios7 sprite-kit game-physics

我有一个身体的场景。

self.player.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.player.size.height / 2];
self.player.physicsBody.dynamic = YES;
self.player.physicsBody.allowsRotation = NO;
self.player.physicsBody.mass = 1;
[self addChild:self.player];

重力设定为-9.8:

self.physicsWorld.gravity = CGVectorMake( 0.0, -9.8 );

我试着检查一下是否正确:

-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
    double delta = currentTime - _pasttime;
    _pasttime = currentTime;
    float ax = (self.player.physicsBody.velocity.dx-self.oldVelocity.dx)/delta;
    float ay = (self.player.physicsBody.velocity.dy-self.oldVelocity.dy)/delta;
    self.oldVelocity = self.player.physicsBody.velocity;
    NSLog(@"The acceleration is: %f %f",ax,ay);
}

我得到以下输出:

2014-04-10 17:12:12.469 PhysicsTest[4508:60b] The acceleration is: 0.000000 -413.161133
2014-04-10 17:12:12.485 PhysicsTest[4508:60b] The acceleration is: 0.000000 -1732.006226
2014-04-10 17:12:12.502 PhysicsTest[4508:60b] The acceleration is: 0.000000 -829.603760
2014-04-10 17:12:12.518 PhysicsTest[4508:60b] The acceleration is: 0.000000 -860.666260
2014-04-10 17:12:12.534 PhysicsTest[4508:60b] The acceleration is: 0.000000 -831.616455
2014-04-10 17:12:12.568 PhysicsTest[4508:60b] The acceleration is: 0.000000 -514.745300
2014-04-10 17:12:12.585 PhysicsTest[4508:60b] The acceleration is: 0.000000 -1667.948853
2014-04-10 17:12:12.601 PhysicsTest[4508:60b] The acceleration is: 0.000000 -839.192383
2014-04-10 17:12:12.618 PhysicsTest[4508:60b] The acceleration is: 0.000000 -807.683167
2014-04-10 17:12:12.651 PhysicsTest[4508:60b] The acceleration is: 0.000000 -523.592285

到底是什么?

0 个答案:

没有答案