Game Development Reference
Reversing the motor speed then simply allows the flipper to spring up and to spring
back down again when the touch ends and the motor speed is reversed again.
joint- > SetMotorSpeed(joint- > GetMotorSpeed() * -1);
The rest is just physics. If the ball is on the flipper, and you touch the screen on the cor-
rect side, the flipper will be accelerated upward, pushing the ball with it. Depending on
where on the flipper the ball lands, it will be propelled more or less straight upward.
In this chapter, you learned how to use the PhysicsEditor tool to define the collision
shapes for the bodies used in the pinball game. With just the ball in place, I illustrated
how you can simulate acceleration toward a point, including how to model the effects
of gravity or magnetism more or less realistically.
I hope this chapter gave you an impression of how much fun physics can be, regardless
of what you may have experienced in physics class. But then again, you didn't build
pinball machines in physics class—or did you?
If you'd like to go beyond this example—for example, using more joints or taking
more control of the collision process—I refer you to the Box2D manual, at
On the other hand, if you need more information about individual classes and structs,
you should look at the Box2D API reference. It's provided in the Documentation
folder of the Box2D download, which you can obtain from ht-
available online, I'm hosting it on my site at www.learn-cocos2d.com/api-
To get help with Box2D, you can check out the official Box2D forums at
www.box2d.org/ forum/index.php and look at the Physics subsection of the