Adding the blocks
Now, we need to add blocks to the game. Click on the block
sprite and add a Physics behavior.
Put the block in front of the cannonball and test it out by firing the cannon! This is shown in the following screenshot:
Destroying the cannonball on a complete stop
The cannonball just sits on the screen and doesn't move. We should then add some logic to destroy it after it hits a block. Add a Compare velocity event to the cannonBall
sprite.
The velocity that we are going to compare is Overall velocity, and we are going to set Comparison to ≤ Less or equal with value 0.1
. This is shown in the following screenshot. The reason we don't want to set the value to zero is that our object may still have a tiny amount of velocity (for instance, of value 0.00001); but as it has not quite made it to zero, the event would not be activated.
When the cannonball almost comes to a complete stop, we want to destroy it. Add a Destroy object action to the event, as shown in the following screenshot...