Jump to content

Game Maker Programming/Creating Objects

From Wikibooks, open books for an open world

In Game Maker, almost everything you see on the screen are called objects.

Creating a sprite

[edit | edit source]

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 frame.

Creating an animated sprite

[edit | edit source]

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.

Sprite options

[edit | edit source]

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

[edit | edit source]

Once the sprite is ready, you can proceed to create the object.

Object properties

[edit | edit source]

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)

Events

[edit | edit source]

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 instances of objects via scripts

[edit | edit source]

Eventually, you will need to create instances 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.