Game Development Reference
In-Depth Information
Depth ordering
An object with a depth that is higher than another, will execute its code first. Oftentimes,
this greatly affects the creation of objects in a room. For example, a button may need to ap-
pear on top of a character in the game when they overlap. For this to happen, the character's
depth value must be higher than the buttons. This will mean that the character's draw event
is run before the button's, which will then result in the button being drawn on top of the
character as desired.
Depth can be both the solution and cause of many problems when creating a game in
GameMaker. One of the most common issues seen is a variable not being recognized with-
in another object. For example, for a variable to be used, it must first be declared at some
point. So if we try to access a variable within another object before it has been initialized,
we will get an error. It is often seen that someone will initialize a variable correctly in an
object, and then have a different object trying to access this variable and getting an error
saying the variable does not exist. The reason this happens is because the instance holding
the variable is created after the other instance, so when the other instance tries to access it,
the variable does not yet exist.
All instances are updated separately within a game room. At every step, GameMaker runs
through each object and executes its code based on the object's depth in the room. An ob-
ject with a higher depth will be updated before an object with a lower depth.
Search WWH ::




Custom Search