whale-pyxel

Pyxel Edit support module. It provides routines for loading sprite sheets and animations created with Pyxel Edit.

const whl = require("whale-core");
const pyxel = require("whale-pyxel");

// ...

var pyxelBuffer = whl.fs.openFile("whale.pyxel").read();
var pyxelDoc = pyxel.Doc(pyxelBuffer);
var bubbleSprite = pyxelDoc.animation("bubble").frameAt(0).sprite.clone();

var canvas = new whl.Canvas(/* ... */);

// Set sprite position to (0, 0).
bubbleSprite.transform = whl.translate(new whl.Vec2(0, 0));

canvas.draw(bubbleSprite);
class whale-pyxel.Animation()

Represents a sequence of frames.

Instances of this class are created by Doc() in the loading process. They cannot be created directly.

Animation.frame(index)
Arguments:
  • index (Number()) – Frame index.

Return type:

whale-pyxel.Frame()

Returns an frame under a given index.

Animation.frameCount()
Return type:

Number

Returns number of frames.

Animation.frameAt(time)
Arguments:
  • time (Number()) – Time in seconds.

Return type:

whale-pyxel.Frame()

Returns a frame at a specified time.

Time gets wrapped around if it is longer than the length of the animation. It makes it easier to play looping animations.

class whale-pyxel.Doc(buffer)
Arguments:

Represents Pyxel Edit document. It contains a sprite sheet image and a list of animations.

Doc.image()
Return type:

whale-core.Image()

Returns a sprite sheet image.

Doc.animation(name)
Arguments:
  • name (String()) – Animation name.

Return type:

whale-pyxel.Animation()

Returns an animation by its name.

class whale-pyxel.Frame(duration, sprite)
Arguments:

Represents an animation frame.

Frame.duration
Type:

Number

Frame.sprite
Type:

whale-core.Sprite()