@antha/graphics-2d
v0.6.0
Published
An Antha mod for rendering 2D graphics to a canvas.
Downloads
1,709
Maintainers
Readme
@antha/graphics-2d
This package provides a pre-built Antha game engine mod that creates and manages a PixiJS application and its canvas.
Install
npm i @antha/graphics-2dUsage
import {AnthaEngine, defineAnthaMod} from '@antha/engine';
import {type AnthaGraphics2dModState, createAnthaGraphics2dMod, Graphics} from '@antha/graphics-2d';
type GameState = AnthaGraphics2dModState & {
hasAddedCircle: boolean;
};
const engine = new AnthaEngine<GameState>({
initState: {
hasAddedCircle: false,
},
mods: [
createAnthaGraphics2dMod(),
defineAnthaMod<GameState>({
modName: 'game-logic',
execute({state}) {
if (!state.pixi?.pixiApplication || state.hasAddedCircle) {
return;
}
state.hasAddedCircle = true;
state.pixi.pixiApplication.stage.addChild(
new Graphics().circle(0, 0, 20).fill('white'),
);
},
}),
],
});
engine.startLoop();