Question

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

Was it helpful?

Solution

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)];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top