npm.io
1.38.0 • Published 5 months ago

@theatrejs/theatrejs

Licence
MIT
Version
1.38.0
Deps
0
Size
1.7 MB
Vulns
0
Weekly
0
Stars
6

Copyright License Bundle Size (Gzipped) NPM Version

Theatre.js

A JavaScript 2D Game Engine focused on creating pixel art games.

Installation

npm install @theatrejs/theatrejs --save

Quick Start

This example does not include the preloading of assets.

import {Actor, Engine, Sprite, Stage, Vector2} from '@theatrejs/theatrejs';

import textureHero from './hero-16x16.png';

class Hero extends Actor {
    onCreate() {
        this.setSprite(new Sprite({
            $sizeTarget: new Vector2(16, 16),
            $texture: textureHero
        }));
    }
}

class Level1 extends Stage {
    onCreate() {
        this.createActor(Hero);
    }
}

const engine = new Engine();
engine.initiate();
engine.createStage(Level1);

With Preloading

Assets are preloaded asynchronously.

asynchronous module
import {Engine, FACTORIES, Sprite, Vector2} from '@theatrejs/theatrejs';

import textureHero from './hero-16x16.png';

class Hero extends FACTORIES.ActorWithPreloadables([FACTORIES.PreloadableTexture(textureHero)]) {
    onCreate() {
        this.setSprite(new Sprite({
            $sizeTarget: new Vector2(16, 16),
            $texture: textureHero
        }));
    }
}

class Level1 extends FACTORIES.StageWithPreloadables([Hero]) {
    onCreate() {
        this.createActor(Hero);
    }
}

const engine = new Engine();
engine.initiate();

await engine.preload(Level1);

engine.createStage(Level1);
synchronous module
...

const engine = new Engine();
engine.initiate();

engine.preload(Level1).then(() => {
    engine.createStage(Level1);
});

API

Keywords