Tutorial

Page 8 of 15

The Collision Event

The next event we will define is a Collision Event with the wall object. The collision event is triggered once for every step of the game that two instances are touching, and an instance is considered as touching when a part of its collision mask (as defined in the Sprite Properties overlaps that of the other instance in a collision. In this case we want the clown to bounce against the wall, changing direction and playing the bounce sound effect at the same time.

To do this, follow these steps:
  1. Press the Add Event button. In the Event Selector click on the Collision Event button and select "obj_wall". The collision event between "obj_clown" and "obj_wall" is now added to the list of events.

  2. Include a Bounce action by dragging it from the page at the right (from the "Move" tab, "Jump" section).

  3. Leave the default values for this action. We are not interested in precise bounces and we want to bounce against solid objects (since we flagged the "obj_wall" object as solid in it's object properties).

  4. Press OK to close the action window.

  5. Select the tab "Main1", and from it include the Play Sound action in the collision event action list.

  6. Drag the Play Sound action below the Bounce action already present. In the action window, click on the icon to the right of the Sound property which will bring up a list of all available sound assets (from the resource tree), and from the list select "snd_bounce". Leave the Loop property as false since we want to play the sound only once, not have it looping constantly.

  7. Press OK to close the action.
That concludes the collision event with the wall object! It now has two actions to be performed (in the given order) when the collision occurs. If you have made a mistake, you can right-click with the mouse on an action you added and, for example, choose Delete to remove the action (or press the <Delete> key on the keyboard). You can also choose Edit Values to change the properties of the action (double-clicking on the action will do the same), and you can drag them up and down to change the order in which they are executed within the action list for the event.



© Copyright YoYo Games Ltd. 2014 All Rights Reserved