0.3.1 • Published 5 years ago

nightrun v0.3.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Nightrun

A Phaser3 library that provides better APIs and some out-of-the-box features:

  • Loading bar for scenes
  • Scenes
  • Items
  • Sprites
  • Monsters

Usage

Install with npm:

npm install nightrun

Nightrun is provided as es6 bundle, without Phaser in it. You can import with:

import {Scene} from 'nightrun';

Classes

Scene

Scene inherits directly from Phaser.Scene, but comes with a loading bar and preload/create/update methods already setup.

import {Scene} from 'nightrun';


class MyScene extends Scene {
    init(phaser) {
        super.init(phaser, {loadingBar: true});
    }
}

Item

A generic item (like a sword or a potion), created with phaser.load.image.

For example, let's say we want to have a sword in our scene:

import {Item} from 'nightrun';

/* In your scene's init (or wherever you create items) */
const item = new Item(this, 'sword', {physics: true});

/* In your scene's preload */
item.preload();

/* In your scene's create */
item.create();

/* Anywhere before calling create
    (I put in in init usually but can be in create too)
*/
item.setSpawn(x, y);

Item will automatically look for assets/sword.png and the item will have this.name set to 'sword'

Sprite

Inherits from Item, but use phaser.load.spritesheet instead.

const sprite = new Sprite(this, 'sword', {frameWidth: 16, frameHeight: 16}, {physics: true});

Monster

Inherits from Sprite, assumes physics is enabled.

const monster = new Monster(this, 'spider', {hp: 1, attack: 1});

/* Fight another Monster instance */
monster.fight(target);

/* Get the attack value */
monster.attack();

/* Checks whether the monster is alive (hp > 0) */
monster.isAlive();

/* In the scene's update, calls sprite.destroy() if dead */
monster.update();
0.3.1

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago