Pinball - Physics to the max!

  • 31 favourites



7,663 visits, 19,590 views



This tutorial hasn't been translated.


This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

The Spring

The spring is used to kick the ball into play. You'll probably find, that every once in a while a strange physics-behavior will trap the ball within the spring - but before that, we have to program the action.

Just use a sprite with a rectangular collision polygon. Actually, we need two sprites of the same size if you want to draw the spring with the mouse. One with and one without physics-behavior. The sprite with the physics-behavior has to be set to "immovable"

The Sprite without the behavior has to be set to invisible and is ony used to locate the mouse cursor. Make sure, that both sprites are at the same location and take a look at the code.

If you examine the code carefully you'll find a little flaw. The impulse to the ball will be given, regardless if the ball is on top of the spring or not...

Now the last active item for this tutorial even if you'll find some more within the porject CAPX.

The Bumper

For the Bumper to work, we need to know the inverse of the angle the ball is hitting the bumper. The easiest way to do this, is to calculate the every tick. We also use this event to make sure, that the ball is allways on top of the layer.

It could happen, that the calculated angle is over 360, so we have to check fot this by codeing:

As you can see above, the reverse angle is stored in an instance variable. This gives you the oportunity to have multi-ball games.

Now the fun part. The bumper is a sprite, that detects the collision with the ball and creates an impulse useing the revers angle of the ball.

Take a look:

We also use this event, to score and play the bumper sound.

This concludes the basic pinball tutorial. Please let me know, if further instruction is needed.


  • Order by
Want to leave a comment? Login or Register an account!