如何改变SKAction中的重力?

时间:2013-10-18 21:10:17

标签: gravity sprite-kit skphysicsbody skaction

我正在使用Sprite Kit制作游戏,我想知道是否有可能制作一个可以改变重力一段时间的SKAction,是吗? 这是我已有的代码:

        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"bal.png"];
        sprite.position = CGPointMake(self.frame.size.width/4 + arc4random() % ((int)self.frame.size.width/2), (self.frame.size.height/2 + arc4random() % ((int)self.frame.size.height/2)));
        sprite.color = [self randomColor];
        sprite.colorBlendFactor = 1.0;
        sprite.xScale = 0.2;
        sprite.yScale = 0.2;
        [self addChild:sprite];
        sprite.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.size.width/2];
        self.physicsWorld.gravity = CGVectorMake(0.0f, -4.0f);

提前致谢!

1 个答案:

答案 0 :(得分:0)

您运行自定义操作块并打开和关闭它,让我知道这是否适合您。

[self runAction:[SKAction sequence:@[[SKAction runBlock:^{ self.physicsWorld.gravity = CGVectorMake(0.0f, -4.0f);}],[SKAction waitForDuration:4],[SKAction runBlock:^{ self.physicsWorld.gravity = CGVectorMake(0.0f, 0.0f);}]]]];