First open Game Maker 8.1 lite edition. Go to File > Advanced Mode. Make sure there is a check mark next to Advanced Mode. We will need this later.
Next will we need to add a sprite. You can do this in a number of ways:
- You can click Resources > Create Sprite
- Click the red pac-man looking icon
- Right click the Sprites folder on the left side of the screen and select Create Sprite.
The best way to create sprites is to use sprite sheets. Here is a template you can use to create you own sprites!
Once you have created your ideal sprite its time to put it into Game Maker. In the Create Sprite screen select Edit Sprite. Then click File > Create from Strip. This allows us to create sprites using a sprite sheet.
Input these values if you are using the template:
- number of image : 2
- images per row : 2
- image width : 16
- image height : 16
- horizontal pixel offset : 1
- vertical pixel offset : 3
- horizontal separation: 2
Name this sprite something similar to heroDown and repeat for all other directions. This blog will only be using 4 direction movement.
Next we will need some object to initialize some global variables. You can create on object using either:
- Click Resources > Create Object
- Click the blue ball icon
- Right click the Objects folder and select Create Object
Name the object playerController or something similar. At the bottom click Add Event and select Create. This event only happens at the creation of the object. On the right hand side click the Control tab. Under the Code sub tab find Execute Code.
Now drag Execute Code under Actions like in the picture above. Double click Execute a piece and code and put this code in:
global.partySize = 3;
for(i = 0; i < global.partySize; i+= 1)
global.partyMember[i] = “Rye”
global.partySize is the max size of your party in the game. We will be using this later on.
Next we do a for loop using global.partySize to determine the size of an array. We create an array global.partyMember[i] = “Rye” You should put the name of your main character in the quotations. I am using Rye.
Ok we are finished with the playerController select OK at the bottom left of the window. Next lets create our player object. Create another object and name it Hero. Make sure to give it a sprite. In the create event put in this code:
// Determines the object’s speed
playerSpeed = 4;
// Determines how fast the object is animated
image_speed = 0.2;
// Determines the order of the characters. 0 is the leader, 1 is the second party member, etc.
partyLocation = 0;
And then create a step event using Step and put in this code:
// Move the object on a grid of 32 x32 with a speed of playerSpeed
// Update sprite if speed is not 0
if playerSpeed > 0
Ok grid_snap and update_sprite are two scripts we need to create so lets do that next.
Create a script – in a similar fashion as you did with objects and sprites. Name the script grid_snap and put this in:
//Usage : grid_snap(speed,placeSnapped)
speed = argument0;
placeSnapped = argument1;
// Check to see if object is snapped to a grid with argument1
if place_snapped(placeSnapped, placeSnapped)
// Change directions
direction = 180
direction = 0
direction = 90;
// Set the speed to zero when no key is pressed
if (place_snapped(placeSnapped,placeSnapped)) && (!keyboard_check(vk_up))&& (!keyboard_check(vk_down))&& (!keyboard_check(vk_left))&&(!keyboard_check(vk_right))
And create another script called updateSprite:
//Usage : update_sprite(partyLocation,direction)
partyNumber = argument0;
direction = argument1;
// Change sprites based on the character
if global.partyMember[partyNumber] = “Rye”
if direction = 0
sprite_index = ryeRight;
if direction = 90
sprite_index = ryeUp;
if direction = 180
sprite_index = ryeLeft;
if direction = 270
sprite_index = ryeDown;
All you have left is to create a room and put the Hero object and playerController object in it. Run the game with F5 and test it out!
Next Post Monday: Party Movement.