Fork me on GitHub

Connecting Sprites to Bodies

06 Aug 2009

Here’s a code snippet for connecting a Rabbyt sprite to a Box2D body. The code assumes that the OpenGL view is transformed to use Box2D world coordinates, that the sprites are scaled down accordingly, and that Box2D and Rabbyt use the same time unit.

Disconnect the sprite immediately before destroying the body, and the sprite will extrapolate the motion of the body. You are now able to remove the sprite smoothly, e.g. by fading it out before removing it.

Latest Blog Posts