@pixelation/engine
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

@pixelation/engine

A simple pixel art game engine.

Installation

npm install @pixelation/engine

Usage

To start using the Pixelation Engine, import this library and call the run lifecycle function. This function requires the following options:

  • screen: An engine.graphics.Screen or engine.graphics.VirtualScreen to draw to.
  • setup: An engine.lifecycle.Setup function which is called before running other code.
  • update: An engine.lifecycle.Update function which is called before rendering each frame.
  • render: An engine.lifecycle.Render function which is called to render each frame.
import * as engine from "@pixelation/engine";

// Create a screen to draw to.
const screen = new engine.graphics.Screen(100, 100);

const setup: engine.lifecycle.Setup = (surface, inputs, audio) => {
    // Add the screen to the page.
    document.body.appendChild(screen.canvas);
};

const update: engine.lifecycle.Update = (surface, inputs, audio, dt, t) => {
    // Here you can handle things like user inputs or process game logic.
    if (inputs.keyboard.pressed("w")) {
        // ...
    }
};

const render: engine.lifecycle.Render = (surface, inputs, dt, t) => {
    // Here you can render to the current rendering target `surface`.
    surface.fillRect(
        0,
        0,
        surface.width,
        surface.height,
        engine.colors.fromHsl(0.65, 0.8, 0.75)
    );
};

engine.lifecycle.run({
    surface: screen,
    setup,
    update,
    render,
});

Examples

For reference examples, please see ./examples.

In addition, the code for the engine is fairly short, so it should be possible to read through to get a better understanding. Don't be intimidated, this stuff ended up being easier than it seems!

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.3.062latest

Version History

VersionDownloads (Last 7 Days)Published
1.3.062
1.2.060
1.1.159
1.1.052
1.0.057

Package Sidebar

Install

npm i @pixelation/engine

Weekly Downloads

290

Version

1.3.0

License

Apache-2.0

Unpacked Size

319 kB

Total Files

17

Last publish

Collaborators

  • jakehamilton