miglib
v1.2.1
Published
A TypeScript graphics and game development library built on p5.js: rendering, particle systems, vector/color math, sprite animation, tilesets, input, and audio.
Maintainers
Readme
MigLib
MigLib is a TypeScript graphics and game development library built on p5.js, providing utilities for rendering, particle systems, vector math, color manipulation, UI elements, and more.
Features
- Screen-based architecture for organizing game/app content
- Powerful graphics and particle system
- Vector and color math utilities
- Asset and sound management
- Gamepad and input helpers
- Easy p5.js integration
Quick Example
import { Starter, MigScreen, Graphics, Assets, Color } from 'miglib';
class MyScreen implements MigScreen {
onShow(graphics: Graphics) {
// Called when this screen is shown
}
onRender(graphics: Graphics) {
graphics.renderText("Hello World", 100, 100, {
size: 24,
color: Color.col(255, 0, 0)
});
}
getButtons() { return []; }
}
// Make sure the p5.js script is loaded globally before this runs.
// Starter creates and wires the p5 instance for you — you don't write
// p5's preload/setup/draw callbacks yourself.
const game = new Starter((assets: Assets) => {
assets.loadImage("myImage", "myImage.png"); // resolved relative to the assets/ folder
return new MyScreen();
});
game.start(); // optionally pass a container element: game.start(myDiv)Example: Sprite Animation
const animator = new Animator();
animator.addAnimation(
"walk",
"character_spritesheet",
[
{ x: 0, y: 0, w: 32, h: 32, duration: 100 },
{ x: 32, y: 0, w: 32, h: 32, duration: 100 },
{ x: 64, y: 0, w: 32, h: 32, duration: 100 },
{ x: 96, y: 0, w: 32, h: 32, duration: 100 }
]
);
animator.play("walk");
// In your render loop:
animator.render(100, 100, graphics, { w: 64, h: 64, scale: 2, alpha: 1 });Example: Playing Sounds
Sound.load("shoot", "sounds/shoot.mp3");
Sound.play("shoot");More Documentation
See the full API and advanced usage in DOCS.md.
