Game Maker Programming/Creating Objects
In Game Maker, almost everything you see on the screen are called objects.
Creating a sprite
Before you can create an object, whether it is a wall or another moving object, you need to create a sprite to display the object. A single frame sprite is created by clicking the Create a sprite icon. Within the new dialogue, click "Load Sprite" and select the bitmap file you want. The sprite in question will appear to the right as a single grame.
Creating an animated sprite
To create an animated sprite, you need to select "Edit Sprite". You can either create images manually, or import them from as an animation strip from the File menu.
In the sprite properties window, you have a few options:
- Precise collision checking
- Smooth edges
- Preload texture - causes the sprite to be loaded on startup rather than as-needed.
- Origin - the point of origin on the sprite
- Bounding box - indicates the collision box on objects using the current sprite.
Creating an object
Once the sprite is ready, you can proceed to create the object.
On the left column, you can set the properties of the object:
- The sprite
- Visible and solid flags
- Depth (rendering order)
- Parent object (inherits properties from the patent)
- Mask (used for collision purposes)
In Game Maker, the various objects react to events. An event handler is created by clicking Add Event.
To react to a given event, create or select an event, and use the icons in the fourth column to choose the actions. The entire palette of actions can be browsed by using the set of tabs on the far right.
Creating objects via scripts
Eventually, you will need to create objects dynamically through the script. This is performed by something similar to the following code:
id = instance_create(x,y,obj);
The return value is the instance id of the newly created object.