Summary of "GameMaker Studio 2: Complete Platformer Tutorial (Part 7: Transitions)"
Video Title
GameMaker Studio 2: Complete Platformer Tutorial (Part 7: Transitions)
Storyline / Context
This tutorial focuses on implementing smooth screen transitions between levels in a platformer game made with GameMaker Studio 2. The goal is to move the player from one room (level) to another using a visually appealing slide transition effect.
Gameplay Highlights & Features Covered
- Creating an invisible, persistent transition controller object that manages transitions across rooms.
- Implementing black bar slide transitions that cover and reveal the screen during level changes.
- Using enums to manage different transition modes (off, next, go to specific room, restart, intro).
- Drawing GUI elements (black bars) that animate during transitions, independent of the camera.
- Adding easing math to make the transition animations smooth and natural (fast start, slow end).
- Using a script (
slide_transition) to trigger transitions easily from anywhere in the game. - Setting up collision triggers that initiate transitions when the player reaches certain areas.
- Temporarily disabling player control during transitions to avoid input issues.
- Restarting the game with a transition effect.
- Debugging common mistakes such as forgetting to add the transition object to the room or forgetting to enable visibility for draw events.
Key Tips & Strategies
- Persistent Object: Make the transition controller object persistent so it carries over between rooms without being destroyed.
- Enums for Modes: Use enums to clearly define transition states, making the code easier to read and manage.
- Draw GUI Event: Use the
Draw GUIevent to draw transition elements so they remain fixed on screen regardless of camera movement. - Easing Transitions: Implement easing by gradually changing the transition percentage with math functions to avoid linear, robotic movement.
- Switch Statement: Use a switch statement for clean handling of different transition modes instead of multiple if-else conditions.
- Script Arguments: Create a reusable script with optional arguments for mode and target room to centralize transition logic.
- Player Control: Add a boolean flag
has_controlto the player object to enable/disable input during transitions. - Instance Creation Code: Use instance creation code in the room editor to set unique properties like target rooms on trigger objects without creating multiple object types.
- Debugging: Always remember to place your transition controller object in the first room and ensure it is visible to allow draw events to run.
Step-by-Step Guide to Implement Transitions
- Duplicate your first room to create a second level for testing.
- Create a persistent, invisible transition controller object (
o_transition). - In the controller’s create event:
- Get screen width and height using
display_get_gui_width()anddisplay_get_gui_height(). - Calculate half the screen height.
- Define an enum for transition modes (
OFF,NEXT,GO_TO,RESTART,INTRO). - Initialize variables like
percent(progress of transition) andtarget(target room).
- Get screen width and height using
- In the step event:
- Update
percentbased on the current mode with easing math. - Use a switch statement to handle actions when
percentreaches 0 or 1 (switch modes, change rooms, restart game).
- Update
- In the draw GUI event:
- Draw two black rectangles that slide from top and bottom based on
percent. - Optionally display debug text showing transition progress.
- Draw two black rectangles that slide from top and bottom based on
- Create a reusable script
slide_transition(mode, target)that sets the mode and target on the transition controller. - Modify player input code to respect a
has_controlflag to disable input during transitions. - Create a trigger object with a collision event with the player that calls
slide_transitionwith the appropriate mode and target room. - Place the transition controller object in the first room and ensure it is visible.
- Test transitions by moving the player into trigger zones and pressing keys to restart.
Common Mistakes & Debugging
- Forgetting to add the transition controller object to the room.
- Not enabling the visible checkbox on the transition controller object (draw events won’t fire if invisible).
- Accessing variables from the wrong object instance (use
other.in collision events). - Not setting the target room in the instance creation code for trigger objects.
- Forgetting to disable player input during transitions leading to unintended behavior.
Additional Notes
- The tutorial emphasizes good coding practices like using enums and switch statements to improve code clarity.
- The presenter suggests using variables instead of hardcoded numbers for easier tweaking.
- The transitions are designed to be flexible and reusable for various types of room changes (next room, specific room, restart).
- The presenter leaves some mistakes in the video intentionally to show real-world debugging and learning moments.
Featured Gamer / Source
- Tutorial by Shaun Spalding (YouTube creator, GameMaker expert)
- Patreon supporters acknowledged at the end (including Dan in a Mule, Alex Ray, Charles Montgomery, Angel Rodriguez, Harold Guidry, Nathaniel)
Category
Gaming