如何随机移动physicsBody?

时间:2014-12-27 10:28:31

标签: ios sprite-kit

我想在场景中随机移动SKSpriteNode。 我尝试的是:

    ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.size.width/2];
    ball.physicsBody.categoryBitMask = BallCategory;
    ball.physicsBody.contactTestBitMask = MainViewCategory;
    ball.physicsBody.affectedByGravity = YES;
    ball.physicsBody.dynamic = YES;
    ball.physicsBody.mass = 0;
    ball.physicsBody.friction = 0.02f;
    ball.physicsBody.linearDamping = 0.0f;
    ball.physicsBody.restitution = 0.1f;
    ball.physicsBody.allowsRotation = YES;
    [ball.physicsBody applyTorque:200];
   [ball.physicsBody applyImpulse:CGVectorMake(200, 600)];

    self.physicsWorld.gravity = CGVectorMake(0, 0);
    self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
    self.physicsBody.dynamic = YES;
    self.physicsBody.affectedByGravity = NO;
    self.physicsBody.restitution = 1.0f;
    self.physicsBody.friction = 0.0f;

但它根据applyImpulse移动特定路径而非随机。

那么如何随机移动SKSpriteNode

0 个答案:

没有答案