| name | ta-phaser-fundamentals |
| description | Configures Phaser games and manages scene lifecycle. Use proactively when setting up Phaser scenes, creating game config, or managing scene transitions. |
| category | techartist |
Phaser Fundamentals for Tech Artists
"2D web games made simple – scenes, sprites, and visual polish."
When to Use This Skill
Use when:
- Setting up Phaser game configuration
- Creating and managing scenes
- Understanding the Phaser lifecycle (preload/create/update)
- Configuring rendering and visual settings
- Setting up scene transitions
Quick Start
const config: Phaser.Types.Core.GameConfig = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: "game-container",
backgroundColor: "#000000",
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
},
scene: [MainScene],
render: {
pixelArt: true,
},
};
new Phaser.Game(config);
Visual Configuration
Pixel Art Mode
const config: Phaser.Types.Core.GameConfig = {
render: {
pixelArt: true,
antialias: false,
roundPixels: false,
},
scene: [MainScene],
};
Camera Setup
create() {
const camera = this.cameras.main;
camera.setBackgroundColor('#2d2d2d');
camera.setBounds(0, 0, 2000, 2000);
camera.setZoom(1);
camera.startFollow(this.player, true, 0.08, 0.08);
}
Scene Visual Lifecycle
export class MainScene extends Phaser.Scene {
preload() {
this.load.image("background", "assets/background.png");
this.load.spritesheet("player", "assets/player.png", {
frameWidth: 32,
frameHeight: 32,
});
this.load.atlas("ui", "assets/ui.png", "assets/ui.json");
}
create() {
this.setupBackground();
this.setupPlayer();
this.setupUI();
}
update(time: number, delta: number) {
this.updateParticles();
this.updateAnimations();
}
private setupBackground() {
this.bg = this.add.tileSprite(
400,
300,
this.scale.width,
this.scale.height,
"background",
);
this.bg.setScrollFactor(0.5);
}
private setupPlayer() {
this.player = this.add.sprite(100, 300, "player");
this.player.play("idle");
}
private setupUI() {
const uiContainer = this.add.container(0, 0);
uiContainer.setScrollFactor(0);
const healthBar = this.add.rectangle(20, 20, 200, 20, 0x00ff00);
const healthText = this.add.text(120, 30, "100", {
fontSize: "16px",
color: "#ffffff",
});
healthText.setOrigin(0.5);
uiContainer.add([healthBar, healthText]);
}
private updateParticles() {
}
private updateAnimations() {
}
}
Visual Best Practices
-
Asset Organization
- Use texture atlases for sprites
- Separate UI assets into own atlas
- Organize by scene/function
-
Performance
- Use object pooling for particles
- Limit active game objects
- Cull off-screen sprites
-
Layering
- Background layer (parallax)
- Game layer (main action)
- Foreground layer (parallax)
- UI layer (fixed, no scroll)
-
Pixel Art
- Set
pixelArt: true in config
- Use
setFilterMode(Phaser.Textures.FilterMode.NEAREST)
- Keep original resolution
Checklist
Visual Data Management
Loading Visual Assets from JSON
When working with JSON level data that defines visual layouts:
preload() {
this.load.atlas('game-assets', 'assets/atlas.png', 'assets/atlas.json');
this.load.json('level001', 'data/levels/level001.json');
}
create() {
const levelData = this.cache.json.get('level001');
levelData.blocks.forEach(block => {
const sprite = this.add.image(block.x, block.y, 'game-assets', block.material);
sprite.setRotation(block.rotation);
sprite.setDepth(block.y);
});
levelData.pigs.forEach(pig => {
const pigSprite = this.add.sprite(pig.x, pig.y, 'game-assets', `pig-${pig.type}`);
pigSprite.setScale(pig.type === 'small' ? 0.6 : pig.type === 'medium' ? 1.0 : 1.4);
});
}
Visual Validation
When validating visual data from JSON:
- Coordinate bounds checking - Ensure all objects are within visible world
- Material type validation - Verify all materials have corresponding sprites
- Scale validation - Check object scales are within reasonable ranges
- Overlap detection - Warn about objects that are too close together
- Depth sorting - Verify Y-based depth sorting for proper layering
Reference