Black Week: −40% Pixor is $19.99 $11.99 until 2 December, on itch.io →

Sprite sheets in GameMaker

In GameMaker one sprite is one animation: a list of frames of the same size, an origin and a speed. Here is how a sprite sheet becomes those sprites, by file name or by cutting a grid, which settings keep pixel art crisp, and how to render eight-direction sheets for GameMaker from a 3D model.

How GameMaker sees a sprite sheet

A GameMaker sprite is one animation: every frame the same size, one origin (the point the sprite is drawn from) and one speed. A character with a walk and an idle on four sides is eight sprites, such as spr_hero_walk_south and spr_hero_idle_west. A sheet that holds all of them has to be cut into those sprites, and there are two ways.

The quick way: _strip file names

Lay one animation out in a single row and end the file name with _strip and the number of frames: golem_walk_strip8.png. Drag the file into GameMaker, or press Import in the Sprite Editor, and GameMaker splits the image into that many frames of equal width, then drops _strip8 from the sprite’s name. A 384 pixel strip with 8 frames gives 48 pixel frames.

A crystal golem walking, eight frames side by side in one row: golem_walk_strip8.png

This is the simplest route when each animation is its own file: one strip per action and side.

Cutting a grid: Convert to Frames

For a sheet with many animations on a grid, import it into a sprite, click Edit Image to open the Image Editor, and choose Image › Convert to Frames (or Image › Import Strip Image to read a file straight into frames). The window asks for:

  • the number of frames and frames per row,
  • the frame width and height, the cell size,
  • offsets to start further in: skip whole cells to begin at a later row, so one sheet gives one sprite per row,
  • separation, if the sheet has gaps between cells.

Repeat it for each row you need as a sprite. With a sheet that has a row per action and side, the walk facing south is one row: start at that row, take that row’s frames.

Origin, speed and collision

  • Origin. In the Sprite Editor set Origin to Custom and type the pixel the character stands on. It must be the same pixel in every frame, or the sprite slides as it animates. Pixor writes it in the sheet’s JSON as meta.pixor.pivot, counted from the frame’s top-left, which is how GameMaker counts too: copy the two numbers as they are.
  • Speed. Set the sprite’s playback speed to the frame rate the sheet was drawn at, in frames per second: a walk rendered at 8 frames a second plays at 8.
  • Collision mask. For characters, a rectangle at the feet usually works better than a precise mask that changes every frame.

Keeping pixels crisp

  • In Game Options, under each platform’s Graphics, untick Interpolate colours between pixels. With it on, every scaled sprite is blurred.
  • In the room’s Viewports and Cameras, make the viewport a whole-number multiple of the camera: a 320 × 180 camera in a 1280 × 720 or 1920 × 1080 viewport. An uneven scale makes some pixels wider than others (mixels).
  • Draw sprites at whole positions, or let the camera snap: a sprite at x = 10.5 is drawn between pixels.
  • Keep image_xscale and image_yscale at whole numbers, and turn sprites by drawing other frames rather than with image_angle.

Sprite sizes has a table of base resolutions and how tall a character looks on each.

Eight directions in GML

Give each side its own sprite, then choose the sprite from the movement direction. GameMaker’s direction counts degrees counter-clockwise from the right, so 0 is right, 90 is up the screen and 270 is down:

// Create event
walk = [spr_golem_walk_East, spr_golem_walk_Northeast, spr_golem_walk_North, spr_golem_walk_Northwest,
        spr_golem_walk_West, spr_golem_walk_Southwest, spr_golem_walk_South, spr_golem_walk_Southeast];

// Step event
if (speed > 0) sprite_index = walk[round(direction / 45) mod 8];

When the character stops, keep the last sprite and swap to the idle of the same side, so it stands facing where it was going. For four sides use round(direction / 90) mod 4 and four sprites.

Rendering the strips from a 3D model

Drawing every side of every animation by hand is the slow part. Pixor renders them from a 3D model (glTF/GLB, FBX, OBJ or MagicaVoxel): in the Scene step, Ring round the model gives one camera per side, all at one size and one Pixels/m, so every sprite of the game shares a pixel size. In the Asset graph, the Arrange node’s Layout sets Grid (a row per action and side) or Strip (every frame in one row), and the Sprites node’s Frames/s cuts each clip at an even rate, which is what a GameMaker sprite plays.

From the command line, one strip per side, named the way GameMaker reads it:

for side in 0:South 45:Southeast 90:East 135:Northeast 180:North 225:Northwest 270:West 315:Southwest; do
  pxr render golem.glb --clip lib:walk --sides ${side%%:*} --fps 8 --layout strip --export json \
    -o sprites/golem_walk_${side##*:}_strip8.png
done

lib:walk is the walk from Pixor’s motion library, fitted to the model’s skeleton: one second long, so 8 frames a second gives the 8 frames the name promises. For a clip of your own, pxr prints each clip’s frame count as it renders; put that number in the name. The JSON beside each strip gives the frame size and the pivot for the origin.

Light that keeps the palette

GameMaker shaders can light sprites from a normal map, but smooth shading brings in colours your palette never had. Tick Light kit in Pixor’s export and it writes the sheet’s colour ramps, normals and a light lookup beside the sheet, with pixor_palette_light.fsh and .vsh, a GameMaker shader. Import the ramp and normal sheets as sprites with the same frames as the colour sheet, each on a separate texture page, set the shader, bind the three maps, the light direction and texel (one pixel of the sheet’s texture page, which the rule against lone highlight pixels needs to find a pixel’s neighbours), then draw_self(); the comments at the top of the shader give every line. A uniform you leave unset, which GameMaker gives 0, takes Pixor’s own choice: the lookup’s highlight thresholds for each ramp (specular, rim), 128 levels, the usual rule against lone highlight pixels, and no fill light; set fill and fill_dir from meta.pixor.light_kit in the JSON for the preset’s fill light. Each lit pixel stays on a step of its own colour ramp. The normal maps guide explains the maps.

Questions

How do I import a sprite sheet into GameMaker?

Either name a one-row strip with _strip and its frame count, such as hero_walk_strip8.png, and drag it into GameMaker, which splits it into eight frames; or import the sheet into a sprite, open it in the Image Editor and use Image › Convert to Frames with the frame count, frame size and offsets.

Why are my pixel-art sprites blurry in GameMaker?

Texture interpolation is on, or the view is scaled by an uneven amount. Turn off Interpolate colours between pixels in Game Options for each platform, and make the viewport a whole-number multiple of the camera, such as a 320 × 180 camera in a 1280 × 720 viewport.

Where should a sprite's origin be?

Where the character stands, the same pixel in every frame, so it does not jitter as it animates. Set Origin to Custom in the Sprite Editor and type that point; a Pixor sheet's JSON gives it as meta.pixor.pivot, counted from the frame's top-left as GameMaker counts it.

Can a GameMaker sprite have frames of different lengths?

Not with one speed per sprite: every frame is shown for the same time. Render the sheet at an even frame rate, or repeat a frame where a pose should hold, or use a Sequence, where each frame can be any length.

Read next

Try it on your own model, free in your browser, or get the full version.

Try in browser Get Pixor