Game Development Reference
In-Depth Information
Parents and collisions
A very useful event in GameMaker is the collision event.
The collision event is triggered when the instance collides with another designated in-
stance. A useful part of parenting objects is that all child objects of that parent will inherit
the collision events defined within the parent object.
For example, you may have a number of different enemy objects—one that stands still, one
that moves, and so on. Let's say you had a bullet that could kill all these enemies. For the
bullet to collide with each different enemy object, it would need a separate collision event,
for example, a collision event for the still enemy, a collision event for the moving enemy,
and so on.
If we parent each enemy type to a single object, then we can make the bullet have a single
collision event with that parent object. Due to the enemy objects being children of that ob-
ject, the collision event is then applied to each of the enemy objects as well. The end result
is the bullet having a single collision event with the parent object and all the children will
be detected as well. This keeps things organized and easy to keep track of. One collision
event is easier to manage than hundreds of them.
Parent objects allow us to group objects that are similar or that should function in much the
same way.
Search WWH ::




Custom Search