Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including e2d-sprite with all npm packages installed. Try it out:

require("e2d/package.json"); // e2d is a peer dependency. var e2dSprite = require("e2d-sprite")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

e2d-sprite v0.1.4

e2d-sprite

A simple sprite implementation for e2d.

Usage

var Sprite = require('e2d-sprite');
var r = e2d.Renderer.create(400, 400);

var spriteObj = new Sprite('http://domain.com/path/to/sprite/sheet.png');
spriteObj.size.set([16, 16]); //16x16 sprite
spriteObj.frame.set([16, 0]); //draw source Rectangle { x: 16, y: 0, width: 16, height: 16 }

//positional information
spriteObj.position.set([200, 200]);//center the sprite on the screen [x, y]
spriteObj.anchor.set([0.5, 0.5]); //anchor in the center


spriteObj.on('load', function() {
  //sprite is loaded
});

r.on('frame', function() {
  spriteObj.rotation += 0.1;

  return r.render(
    spriteObj.render()
  );
});

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free