Description

Spritesheet is a Sprites collection in an image. This class aims to crop the image, retrieve each Sprite by assigning an identifier

Usage

Constructor

  • image {String}

    ID image

  • params {Object}

    See the method "set"

Example

var canvas = CE.defines("canvas_id").
    extend(Spritesheet).
    ready(function() {
        canvas.Scene.call("MyScene");
    });

canvas.Scene.new({
    name: "MyScene",
    materials: {
        images: {
            my_spritesheet: "path/to/spritesheet.png"
        }
    },
    ready: function(stage) {
         var el = this.createElement();
         var spritesheet = canvas.Spritesheet.new("my_spritesheet", {

            grid: [{
                size: [4, 5],
                tile: [107, 107],
                set: ["play", "player_hover", "zoom_p", "zoom_m"]
            }],
            btn_play: [433, 33, 215, 188]

         });
         spritesheet.draw(el, "play");
         stage.append(el);
    }
});

Methods

set

Assigns an identifier to an area of the spritesheet. A grid can be defined to be faster.

exist

`(1.3.1)` Returns true if identifier in sprite sheet exists

draw

Draw a Sprite on the element

pattern

Repeat an image of SpriteSheet. Do not forget to draw the pattern with "fillRect" or "fill"

Discussion