Tutorial
Page 5 of 15
Objects, Events and Actions
Having created the sprites and sounds does not mean that anything is going to happen in your game. Sprites are only the images for game objects and we have not yet defined any game objects. Similarly,
sounds will only play if we tell them to be played, and we can only tell them to be played from a game object too. So we need to create our two game objects next...
Instances
However, before we do this you will have to understand the basic way in which GameMaker: Studio operates. As we have indicated before, in a game we have a number of different game objects and
during the running of the game one or more instances of these game objects will be present on the screen or, more general, in the game world. Note that there can be multiple instances of the same
game object. So for example, in our "Catch the Clown" game there will be one wall object, but a large number of instances of that object surrounding the playing field, and there will be just one instance of the
clown object. Think of objects as a blueprint, and instances as something created from that blueprint.
Events
Instances of game objects don’t do anything unless you tell them how to act, and you do this by indicating how the instances of the object must react to events that happen. There are many different
events that can happen as your game progresses, but the first (and often most important) event that we are going to look at is when the instance is created. This event is called the Create Event, and
more often than not some action is required here, for example we must tell the instance of the clown object that it should start moving in a particular direction.
Another important event happens when two instances collide with each other and is called a Collision Event. For example, when the instance of the clown collides with an instance of the wall, the clown
must react and change its direction of motion.
Other events happen when the player presses a key on the keyboard or clicks with mouse on an instance etc... For the clown in our game we will use a Mouse Event to make it react to a press of the
mouse on it.
Actions
To indicate what must happen in any given event, you must specify D'n'D actions. There are many useful actions for you to choose from, for example there in an action that sets the instance in motion in a
particular direction, or there is an action to change the score, or an action to play sounds.
So, to sum up the above, defining a game object that we can create instances of consists of:
- Giving the object a name and assigning a sprite (if necessary)
- Setting the initial object properties
- Adding events which will be triggered by specific things in our game
- Adding actions to the events to have our instances of the object act/react in different ways
Before continuing, just lets revise a very important distinction that you should always keep in mind, and that is the distinction between objects and instances of those objects. An object defines
a particular game object with its behaviour (that is, its reaction to events). Of this object there can be one or more instances in the game and these instances will act according to the defined behaviour. Stated
differently, an object is an abstract thing - like in normal life, we can talk about a chair as an abstract object that you can sit on, but we can also talk about a particular chair, that is an instance of the chair object,
which actually exists in our home.
© Copyright YoYo Games Ltd. 2014 All Rights Reserved