Get started with spritejs CDN

MIT licensed

Lightweight library: 2D sprites, animations with Sprite.js.

Tags:
  • spritejs
  • canvas
  • graphics
  • rendering
  • render
  • svg-path
  • svg
  • webgl2
  • webgl
  • 3d
  • 2d

Stable version

Copied!

How to start using spritejs CDN


// Include SpriteJS library
const SpriteJS = require('spritejs');

// Create a new SpriteJS scene
const scene = new SpriteJS.Scene();

// Define an image sprite sheet
const image = new Image();
image.src = 'path/to/your/sprite-sheet.png';

// Load the image and create a new sprite sheet
image.onload = function() {
  const spriteSheet = new SpriteJS.SpriteSheet({
    image: image,
    rows: 2,
    cols: 3
  });

  // Create individual sprites from the sprite sheet
  const sprite1 = new SpriteJS.Sprite({
    texture: spriteSheet.getTextureFor('0-0')
  });

  const sprite2 = new SpriteJS.Sprite({
    texture: spriteSheet.getTextureFor('1-1')
  });

  // Add the sprites to the scene
  scene.addChild(sprite1);
  scene.addChild(sprite2);

  // Set the size and position of each sprite
  sprite1.width = 50;
  sprite1.height = 50;
  sprite1.x = 50;
  sprite1.y = 50;

  sprite2.width = 50;
  sprite2.height = 50;
  sprite2.x = 150;
  sprite2.y = 150;

  // Append the scene to the body of the document
  document.body.appendChild(scene.el);
};
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions