Summary of "GameMaker Studio 2: Complete Platformer Tutorial (Part 2: Animated Player)"
GameMaker Studio 2: Complete Platformer Tutorial (Part 2: Animated Player) - Summary
Storyline / Context
This tutorial continues a platformer series where the player character, initially a simple green square, is replaced with animated sprites representing different states: idle, running, and jumping/falling. The goal is to enhance the player object with proper animations, collision handling, and directional facing.
Gameplay Highlights & Features Implemented
- Replacing the placeholder square player with actual animated sprites.
- Using three different sprites for the player:
- Idle (standing still)
- Running (animated)
- Airborne (jumping/falling, two frames for up and down)
- Proper collision mask setup to better fit the player sprite and avoid unwanted overlaps.
- Layer management to ensure the player always renders in front of walls.
- Animations triggered based on player state (on ground, moving, jumping, falling).
- player sprite flipping horizontally based on movement direction.
Step-by-Step Guide / Key Tips
- Importing Sprites:
- Use the import feature to bring in pre-made sprites.
- Naming convention: include "strip" and the number of frames (e.g.,
s_player_R_strip4) to auto-split sprite sheets into frames. - Use a single collision mask (from the idle sprite) for all player sprites for consistency.
- collision mask Setup:
- Change from automatic to manual collision mask.
- Shrink the collision box to be smaller than the sprite for better gameplay feel.
- Always use a smaller collision box rather than a bigger one.
- Layer Management:
- Separate player and wall objects into different layers.
- Place the player layer above the wall layer to ensure correct rendering order.
- Animation Logic:
- Keep animation code separate from movement logic for clarity.
- Use the
stepevent to update the sprite based on player state. - Check if the player is airborne by detecting collision one pixel below (
place_meeting(x, y+1, wall)). - If airborne:
- Set sprite to airborne sprite.
- Set animation speed to zero (no animation).
- Choose frame based on vertical speed (
vsp):- If falling (
vsp > 0), show falling frame. - If rising (
vsp < 0), show jumping frame.
- If falling (
- If on the ground:
- Set animation speed to 1 (normal speed).
- If horizontal speed (
hsp) is zero, set sprite to idle. - Else set sprite to running animation.
- Sprite Flipping (Direction Facing):
- All sprites face right by default.
- Flip sprite horizontally by setting
image_x_scaleto 1 or -1. - Use the sign of horizontal speed (
sign(hsp)) to determine facing direction:- Positive
hsp→ face right (image_x_scale = 1) - Negative
hsp→ face left (image_x_scale = -1)
- Positive
- Only flip sprite when moving (when
hspis not zero).
- Coding Best Practices & Notes:
- Use
==for comparisons in if-statements,=for assignments. - Use inline if-statements for concise code.
- Avoid redundant collision checks by storing results in variables (optimization tip).
- Set animation speeds in the sprite resource,
image_speedacts as a multiplier. - Keep animation-related code at the end of the step event for clarity.
- Use
Next Steps Preview
- Adding arms to the player sprite.
- Implementing weapons and shooting projectiles.
- Making weapons follow the mouse cursor.
Credits / Sources
- Tutorial by the video creator (name not explicitly stated).
- Special thanks to Patreon supporters: Ino mu, Giles Montgomery, Dan Angel Rodriguez, Harold Gidry, Roxom, Jason McMillan, Owen Morgan.
This summary captures the main points of the tutorial including the process of importing and managing sprites, handling collisions and layers, implementing animation states, and flipping the player sprite direction based on movement.
Category
Gaming