This ERB Custom boilerplate includes Phaser 3 as an optional game engine module. Phaser is a fast, free, and fun open source HTML5 game framework that provides WebGL and Canvas rendering for desktop and mobile web browsers.
- ✅ Phaser 3.87 - Latest stable version
- ✅ React Component Wrapper - Seamless integration with React
- ✅ Demo Scene - Interactive example with physics and particles
- ✅ TypeScript Support - Full type definitions included
- ✅ Physics Engine - Arcade physics pre-configured
- ✅ Module Status - Real-time availability indicator
npm installThis will install phaser@^3.87.0 along with all other dependencies.
Run the app and click the "🎮 Phaser Demo" button or navigate via the dock to see the interactive demo scene.
Create a new scene in src/renderer/phaser/scenes/:
// src/renderer/phaser/scenes/MyGame.ts
import Phaser from 'phaser';
export default class MyGame extends Phaser.Scene {
constructor() {
super({ key: 'MyGame' });
}
preload() {
// Load assets
this.load.image('player', 'assets/player.png');
}
create() {
// Initialize game objects
const player = this.add.sprite(400, 300, 'player');
}
update(time: number, delta: number) {
// Game logic
}
}Import and add your scene to the PhaserGame component:
import PhaserGame from './phaser/PhaserGame';
import MyGame from './phaser/scenes/MyGame';
import DemoScene from './phaser/scenes/DemoScene';
// In your component:
<PhaserGame
width={800}
height={600}
scenes={[MyGame, DemoScene]}
/>src/renderer/phaser/
├── PhaserGame.tsx # React wrapper component
├── PhaserDemo.tsx # Demo page with documentation
└── scenes/
└── DemoScene.ts # Example scene with physics & particles
- Arcade Physics (lightweight, fast)
- Matter.js Physics (advanced, realistic)
- Support for sprites, groups, and collision detection
- WebGL renderer (hardware accelerated)
- Canvas fallback for older devices
- Built-in camera system with effects
- Mouse and touch support
- Keyboard input handling
- Gamepad/controller support
- Image, sprite sheet, and atlas loading
- Audio (Web Audio API and HTML5 Audio)
- JSON, XML, and binary data
- Asset pack loading
- Sprite sheet animations
- Tweens and timelines
- Particle systems
- Shader effects
The default configuration in PhaserGame.tsx:
const config: Phaser.Types.Core.GameConfig = {
type: Phaser.AUTO, // WebGL with Canvas fallback
width: 800,
height: 600,
backgroundColor: '#1a1a2e',
physics: {
default: 'arcade',
arcade: {
gravity: { x: 0, y: 0 },
debug: false, // Set to true for debug rendering
},
},
scene: scenes,
scale: {
mode: Phaser.Scale.FIT, // Scale to fit container
autoCenter: Phaser.Scale.CENTER_BOTH,
},
render: {
antialias: true,
pixelArt: false, // Set to true for pixel art games
},
};Perfect for platformers, shooters, puzzle games, and more.
Create engaging data visualizations and infographics.
Build interactive learning experiences and simulations.
Game editors, level designers, animation tools.
Rapid prototyping of game concepts and mechanics.
preload() {
// Organize assets by type
this.load.setPath('assets/');
this.load.image('sprites/player', 'player.png');
this.load.audio('sounds/jump', 'jump.mp3');
this.load.json('data/levels', 'levels.json');
}// Switch scenes
this.scene.start('NextScene', { score: 100 });
// Pause/resume
this.scene.pause('GameScene');
this.scene.resume('GameScene');
// Run scenes in parallel
this.scene.launch('UIScene');shutdown() {
// Clean up resources when scene ends
this.textures.remove('tempTexture');
this.sound.removeAll();
}- Use texture atlases instead of individual images
- Enable texture compression for large games
- Pool game objects instead of creating/destroying
- Use
update()sparingly - consider event-driven logic - Enable
pixelArt: truefor retro games (better performance)
- Check that the container element exists when game initializes
- Verify scene key is correct
- Check browser console for WebGL errors
- Ensure asset paths are correct (relative to public folder)
- Check CORS settings if loading from external URLs
- Verify files are included in webpack config
- Enable debug mode to check physics body counts
- Monitor texture memory usage
- Consider using smaller sprite sheets
- Reduce particle counts
Phaser 3 is released under the MIT License. See the Phaser License for details.
- Explore the demo scene code in
src/renderer/phaser/scenes/DemoScene.ts - Read the Official Phaser Tutorial
- Browse Phaser Examples for inspiration
- Join the Phaser Community for help
Happy game development! 🎮