HT Games
Home  >> Games

Creating a 2.5D Game in GameMaker Studio 2: Complete Guide with Code Examples

2.5D = 2D gameplay with simulated depth (parallax, scaling, layering). GameMaker excels at this. Here's a practical framework:

Core Techniques

1. Depth Ordering (Z-Index)

// Create Event
depth = -y; // Higher on screen = lower depth = drawn on top
  • Objects with lower depth draw in front.
  • Use depth = -y + offset for multi-tile objects.

2. Parallax Backgrounds


// Create multiple background objects (obj_bg_far, obj_bg_mid, obj_bg_near)
// Step Event (each)
obj_bg_far.x -= 0.25; // Slowest
obj_bg_mid.x -= 0.5;
obj_bg_near.x -= 1.0; // Fastest
  • Layer backgrounds by distance; loop x when off-screen.
  • Use draw_background_ext for scaling/tiling control.

3. Perspective Scaling (Fake 3D)


// Step Event
var scale = 1 - (y / room_height) * 0.5; // 1.0 at top, 0.5 at bottom
image_xscale = scale;
image_yscale = scale;
  • Objects shrink as they move "up" (away).
  • Adjust divisor for intensity.

4. Lighting & Shadows

  • Built-in Lights: light_define_direction(), light_define_point() — simple, vertex-lit.
  • Surface/Shader Shadows: Render objects to a surface, apply blur + offset for drop shadows.
  • Normal Maps: Use shaders (Vertex/Fragment) for per-pixel lighting on 2D sprites.

Minimal 2.5D Platformer Template

// obj_player Create
depth = -y;
hsp = 0; vsp = 0;
grav = 0.5; jump = -10;

// obj_player Step
hsp = (keyboard_check(vk_right) - keyboard_check(vk_left)) * 4;
vsp += grav;
if (place_meeting(x, y+1, obj_solid) && keyboard_check_pressed(vk_up)) vsp = jump;
x += hsp; y += vsp;
// Collision resolution omitted for brevity

// obj_bg_far Step
x -= 0.3;
if (x <= -sprite_width) x += sprite_width * 2;

// obj_bg_mid Step
x -= 0.7;
if (x <= -sprite_width) x += sprite_width * 2;

Pro Tips

  • Use Layers: GameMaker's layer system (background, instances, foreground) handles depth automatically—assign instances to layers by layer = "Instances_Far" etc.
  • Tilemaps: For static geometry, tilemaps are faster than objects.
  • Camera: Use camera_create_view with camera_follow for smooth tracking.
  • Shaders: Learn GLSL ES for custom lighting, distortion, water, CRT effects.

Start simple: Depth + parallax → scaling → shadows. Iterate visually. 2.5D is an illusion—sell it with consistency.


https://www.htfbw.com © HT Games