Import a 4-direction sprite sheet in Phaser 3.
Phaser 3 is the fastest engine for browser RPGs and vibe-coded web games — if you configure pixel filtering, frame indices, and foot-level Arcade Physics hitboxes right. Test our live 4×4 sheet below with WASD/arrows, then copy the exact loader into your scene.
Option A (Recommended): Load atlas_96.json with this.load.atlas
Every schema-v2 PixelForge ZIP (including starter-pack.zip) ships pre-built Phaser 3 / TexturePacker JSON Hash sidecars at processed/phaser/atlas_96.json and atlas_48.json. Named frames (down_01..04, left_01..04, right_01..04, up_01..04) eliminate off-by-one frame index bugs:
import Phaser from 'phaser';
export class WorldScene extends Phaser.Scene {
private player!: Phaser.Types.Physics.Arcade.SpriteWithDynamicBody;
private cursors!: Phaser.Types.Input.Keyboard.CursorKeys;
private facing: 'down' | 'left' | 'right' | 'up' = 'down';
preload() {
this.load.atlas(
'hero',
'/assets/player/processed/sprite-sheet-96-transparent.png',
'/assets/player/processed/phaser/atlas_96.json'
);
}
create() {
for (const dir of ['down', 'left', 'right', 'up'] as const) {
this.anims.create({
key: `walk-${dir}`,
frames: this.anims.generateFrameNames('hero', {
prefix: `${dir}_`,
start: 1,
end: 4,
zeroPad: 2,
}),
frameRate: 1000 / 135, // ~7.41 FPS
repeat: -1,
});
}
this.player = this.physics.add.sprite(320, 240, 'hero', 'down_01');
// Lock collision box to the lower body / boots (foot_baseline_y = 90)
this.player.body.setSize(48, 46).setOffset(24, 44);
this.cursors = this.input.keyboard!.createCursorKeys();
}
update() {
const speed = 150;
const body = this.player.body;
body.setVelocity(0);
if (this.cursors.left.isDown) { body.setVelocityX(-speed); this.facing = 'left'; }
else if (this.cursors.right.isDown) { body.setVelocityX(speed); this.facing = 'right'; }
if (this.cursors.up.isDown) { body.setVelocityY(-speed); this.facing = 'up'; }
else if (this.cursors.down.isDown) { body.setVelocityY(speed); this.facing = 'down'; }
body.velocity.normalize().scale(speed);
if (body.velocity.lengthSq() > 0) {
this.player.anims.play(`walk-${this.facing}`, true);
} else {
this.player.anims.stop();
this.player.setFrame(`${this.facing}_01`); // idle_column = 0
}
// Top-down Y-sort by boots
this.player.setDepth(this.player.y);
}
}Option B: Load any 4×4 PNG directly with this.load.spritesheet
If you only want a single PNG file in public/assets/, slice by frameWidth: 96, frameHeight: 96 (or 48, 48 on the 48px sheet):
// Game config: always enable pixelArt + roundPixels! const config: Phaser.Types.Core.GameConfig = { type: Phaser.AUTO, width: 640, height: 360, pixelArt: true, roundPixels: true, physics: { default: 'arcade', arcade: { debug: false } }, scene: [WorldScene], }; // Inside preload(): this.load.spritesheet('hero', '/assets/sprite-sheet-96-transparent.png', { frameWidth: 96, frameHeight: 96, }); // Row indices: down = 0..3, left = 4..7, right = 8..11, up = 12..15 (idle = 0, 4, 8, 12)
3 Phaser pixel-art gotchas (and instant fixes)
- Blurry edges on HiDPI / Retina screens: Missing
pixelArt: truedefaults WebGL toLINEARfiltering. AddpixelArt: trueinGameConfigandimage-rendering: pixelatedon the parent canvas CSS. (More engine fixes in Fix Blurry Pixel Art Sprites.) - 1px shimmer or tile seams when the camera follows the player: Enable
roundPixels: trueon both theGameConfigandthis.cameras.main.setRoundPixels(true). - Head colliding with ceilings in top-down rooms: Default Arcade Physics bodies wrap all
96×96pixels. Shrink the body to the lower torso/feet withbody.setSize(48, 46).setOffset(24, 44)(orsetSize(24, 23).setOffset(12, 22)on 48px sheets) so the character's head overlaps north walls naturally like classic Zelda / Pokémon.
Frequently asked questions
Both work cleanly with PixelForge sheets because every cell is an exact 96×96 (or 48×48) grid. this.load.atlas with processed/phaser/atlas_96.json is slightly nicer for readability and AI coding agents because frame names like down_01 are self-documenting instead of numeric indices 0..15.
Phaser defaults to linear texture interpolation unless you pass pixelArt: true at the top level of your Phaser.Game config object. Setting pixelArt: true switches all WebGL and Canvas textures to crisp nearest-neighbor rendering.
Download /samples/starter-pack.zip ($0, CC0 commercial license) — it contains the exact sprite-sheet-96-transparent.png, sprite-sheet-48-transparent.png, atlas_96.json, and atlas_48.json running in the sandbox above.
Put anyone into your game.
$5 · one photo · 4-direction walk pack (96px, 48px, RPG Maker & Phaser atlas) · 3 free retries · no subscription
Make a sprite — $5