A2 - Creating a Character
In this assignment, you will create a chracter and integrate it into your game.
Resources for this Assignment
- Video of me going through all the steps
- Vitruvian Studio - for creating chracters
Code to paste into your object (when you get to that step):
var move_speed = 4;
var up_sprite = player_walk_up
var down_sprite = player_walk_down
var left_sprite = player_walk_left
var right_sprite = player_walk_right
// Input
var hInput = keyboard_check(vk_right) - keyboard_check(vk_left);
var vInput = keyboard_check(vk_down) - keyboard_check(vk_up);
// Movement
x += hInput * move_speed;
y += vInput * move_speed;
// Animation - prioritize horizontal movement if both are pressed
if (hInput != 0) {
if (hInput > 0) {
sprite_index = right_sprite;
} else {
sprite_index = left_sprite;
}
} else if (vInput != 0) {
if (vInput > 0) {
sprite_index = down_sprite;
} else {
sprite_index = up_sprite;
}
}
// Play animation when moving, stop when idle
if (hInput != 0 || vInput != 0) {
image_speed = 1; // Adjust to control animation speed
} else {
image_speed = 0;
image_index = 0; // Optional: freeze on first frame
}
Part 1 Steps - Creating the Character
-
Go to Vitruvian Studio
-
Go through the various options on the lefthand side to create a character to your liking
-
Click the purple Save button near the righthand side
-
Click the purple renderings button - at the far right, last button down in the group of three, with an icon that looks like a folder with triangles on it.
-
Click Download All.
-
Unzip the folder.
Part 2 Steps - Creating the Sprites
Note - by GameMaker's definition, a "Sprite" is either an image or an animation.
-
From the folder you unzipped, drag the
walk.pngimage into theSpritesfolder in GameMaker's asset manager. -
In the window that opens, click the Edit Image button
-
In the Image menu at the very top, choose Convert to Frames. Use the following settings:
- Number of Frames: 8
- Frames per Row: 8
- Frame Width: 64
- Frame Height: 64
-
Click the Convert button
-
Back in the Image menu, select Auto Trim All Frames
-
You can test the animation by pressing the play button (triangle icon). You will probably want to slow down the frame rate - look for the FPS setting at the bottom-left of the screen.
-
Rename the sprite
player_walk_up -
Repeat Part 2 three more times, for the other animations (right, left, and down). In the Convert to Frames step, you'll need to adjust the Vertical Cell Offset setting to select the row from the spritesheet you want to isolate.
Part 3 Steps - Creating and Adding the Player Object
-
In the asset manager, right-click the Object folders and create a new object.
-
In the window that opens, click the No Sprite button, and choose the
player_walk_downsprite -
In the Events window, click Add Event --> Step --> Step
-
Choose GML Code
-
Paste in the code at the top of this assignment. On lines 2-5, make sure the sprite names (on the right of each
=sign) match the names you chose for your sprites. -
Close the object and open your room
-
Drag the player from the asset manager to a location of your choice on the room map
-
Run the project (triangle button in the top icon bar) and use the arrow keys to move your player