A modern template for PixiJS development with TypeScript and Rollup.
- PixiJS v8
- Rollup for efficient bundling
- TypeScript with ESM and latest ECMAScript features
- Hot Module Reloading for fast development
- Prettier for code formatting
- Clone this repository (or use this template)
- Install dependencies:
npm install- Start development server:
npm start- Build for production:
npm run buildThe file game.ts contains essential components for game management:
-
Main Components
app: Main PixiJS application instancemouse: Point representing mouse positionticker: Shared game loop managercontainer: Main application stage
-
Time Management
getDeltaTime(): Returns time elapsed since last frame in secondsgetOscillation(duration, amplitude): Creates a sinusoidal oscillation with given duration and amplitude
-
Sprite Management
getSprite(name): Loads and returns a sprite from assetsgetAnimatedSprite(name, options): Loads and returns an animated sprite from assetsresizeAsBackground(sprite): Resizes a sprite to cover the screen
-
Utilities
toRadians(degrees)/toDegrees(radians): Angle conversiondist(a, b): Calculates distance between two pointsgetWidth()/getHeight(): Window dimensionspause()/play()/isPaused(): Game loop control
The file keyboard.ts handles keyboard inputs:
-
Key Class
- Manages key states (pressed/released)
- Emits events on state changes
- Tracks key press duration
-
Predefined Keys
up,down,left,right: Directional keysspace: Spacebar
-
Global Management
keys: Set containing all registered keys- Event listeners for
keydownandkeyup
npm start- Start development server with hot reloadingnpm run build- Build for productionnpm run format- Format code with Prettier
