npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

stupid-sprite

2.1.0 • Public • Published

Stupid Sprite

A simple sprite lib for animating sprites.

All sprites need to be stacked vertically. (Remember that some devices/browsers dont support large images).

Create

// Import sprite & tick
var Sprite = require('stupid-sprite');
var Tick = require('stupid-tick');
 
// Create tick
var tick = Tick({fps:24});
 
// Select canvas & images
var canvas = document.querySelector('canvas');
var images = [
    'image_01.png',
    'image_02.png',
    'image_03.png',
    'image_04.png',
];
 
// Create sprite
var sprite = Sprite({
    tick:tick, 
    canvas: canvas
});
 
// Load images
sprite
.load(images)
.success(function(){
    // Play sprite when images is loaded
    sprite.play();
});

Options

var sprite = Sprite({
    tick:tick, 
    canvas: canvas,
    loop: false // Sprite doesn't loop
});

Events

sprite.on('ended', function(){
    // Sprite has looped/ended
});
 
sprite.on('update', function(_frame){
    // On every frame update.
});

Methods

sprite.play(Number); // Number is optional
sprite.pause(Number); // Number is optional
sprite.stop(Number); // Number is optional
 
sprite.isPlaying() // Tells if sprite is playing [Boolean]
 
sprite.loop(Boolean); // Toogle loop. Boolean is optional.
sprite.getLoop(); // Get loop Boolean.
 
sprite.reverse(Boolean) // Reverses direction. Boolean is optional.
sprite.getReverse(); // Get reverse Boolean
 
sprite.getFrame(); // Returns current frame [Number]
sprite.getEndFrame(); // Returns end/last frame [Number]
 
sprite.hasLoaded(); // Returns true if images is loaded, false if not [Boolean]

Keywords

none

install

npm i stupid-sprite

Downloadsweekly downloads

14

version

2.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability