2
votes

How would I create things like balloons and bubbles in a Sprite Kit physics world?

Their physics bodies' should be affected by gravity, right? But is there no way to set individual gravity per sprite?

Update: According to a forum post this is how Box2d does the local gravity: Maybe it can be replicated for games using other physics engines.

b.m_linearVelocity.x += step.dt * (gravity.x + b.m_invMass * b.m_force.x);
b.m_linearVelocity.y += step.dt * (gravity.y + b.m_invMass * b.m_force.y);

From http://www.box2d.org/forum/viewtopic.php?p=27576&sid=24a8448ae05c9e3c97a3f8c02aa5a175#p27576

1
Box2d has the individual gravity for individual sprites. I wonder if I should just try to use Box2d with sprite kit and not use SKPhysicsBody and the other physics code of Sprite Kit at all. - Jonny
I also noticed that there is no such thing in Chipmunk (cocos2d 3) either... :-P - Jonny

1 Answers

1
votes

No, there is no way to set individual gravity per sprite, but you can apply force to the bubble:

- (void)update:(NSTimeInterval)currentTime {
    [bubbleNode.physicsBody applyForce:CGVectorMake(0,300)];
}