Phaser Development
Phaser 3 Development Guide
Phaser 3 is a fast, free, and open-source HTML5 game framework. This skill provides guidance for architecting complex 2D games, specifically integrated with modern React/TypeScript stacks.
Core Concepts
1. The Game Instance
Always manage the game instance lifecycle. In React, use useRef for the container and useEffect to initialize/destroy.
const gameRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const config = { ... };
const game = new Phaser.Game(config);
return () => game.destroy(true);
}, []);
2. Scenes
Scenes are the building blocks. Use multiple scenes for overlays (UI, Hud).
preload(): Load assets (images, audio, json).create(): Initialize objects, input, and animations.update(time, delta): Main game loop logic.
3. GameObjects
- Sprites/Images: Textured objects.
- Shapes (Arc, Rectangle): Useful for UI and placeholders.
- Text: Digital typography. Always use
String(value)for numbers to satisfy strict linting.
4. Input & Interactivity
Enable interactivity via .setInteractive().
object.setInteractive().on('pointerdown', (pointer) => {
// Handle click/touch
});
5. Tweens & Animations
Use Tweens for smooth transitions instead of manual update math where possible.
scene.tweens.add({
targets: object,
alpha: 0,
duration: 1000,
onComplete: () => object.destroy()
});
React Integration Patterns
Bridging Game & React State
Pass callbacks from React props to the Phaser Scene via the scene init or data parameter.
const PhaserGame = ({ onEvent }) => {
useEffect(() => {
class MyScene extends Phaser.Scene {
create() {
this.events.on('custom-event', onEvent);
}
}
}, [onEvent]);
};
Performance & Mobile Optimization
- Resolution: Use
scale: { mode: Phaser.Scale.FIT, autoCenter: Phaser.Scale.CENTER_BOTH }. - Texture Atlases: Combine images to reduce draw calls.
- Destruction: Always cleanup objects in
onCompleteor Sceneshutdown. - Input: Use
input.setPollAlways()for smoother mouse tracking if needed, but be mindful of CPU.
TypeScript Best Practices
- Define interfaces for
SceneData. - Use specific types for GameObjects (e.g.,
Phaser.GameObjects.Sprite). - Avoid
anyin scene events by typing the event emitter.
More from involvex/aetheris
react-patterns
Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.
2ethskills
Use when a request involves Ethereum, the EVM, or blockchain systems. Applies to building, auditing, deploying, or interacting with smart contracts, dApps, wallets, or DeFi protocols. Covers Solidity development, contract addresses, token standards (ERC-20, ERC-721, ERC-4626, etc.), Layer 2 networks (Base, Arbitrum, Optimism, zkSync, Polygon), and integrations with DeFi protocols such as Uniswap, Aave, and Curve. Includes topics such as gas costs, contract decimals, oracle safety, reentrancy, MEV, bridging, wallets, querying data from onchain, production deployment, and protocol evolution (EIP lifecycle, fork tracking, upcoming changes).
2erc-721
Add an ERC-721 NFT contract to a Scaffold-ETH 2 project. Use when the user wants to: create an NFT collection, deploy an ERC-721, add NFT minting, build an NFT gallery or transfer UI, or work with non-fungible tokens in SE-2.
1planning-with-files
Implements Manus-style file-based planning for complex tasks. Creates task_plan.md, findings.md, and progress.md. Use when starting complex multi-step tasks, research projects, or any task requirin...
1ponder
Integrate Ponder into a Scaffold-ETH 2 project for blockchain event indexing. Use when the user wants to: index contract events, add a blockchain backend, set up GraphQL for onchain data, use Ponder with SE-2, or build an indexer for their dApp.
1erc-20
Add an ERC-20 token contract to a Scaffold-ETH 2 project. Use when the user wants to: create a fungible token, deploy an ERC-20, add token minting, build a token transfer UI, or work with ERC-20 tokens in SE-2.
1