0

I am making a game in Sprite Kit and I am wondering if it is possible to make a SKAction which changes he gravity for a while, is it? This is the code I already have:

        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);

Thanks in advance!

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Vince
  • 648
  • 1
  • 7
  • 17

1 Answers1

0

you run custom action blocks and turn it on and off, let me know if this works for you.

[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);}]]]];
user2421700
  • 149
  • 8