me.Renderer.Texture(atlas, sourceopt, cachedopt)

new Texture(atlas, sourceopt, cachedopt)

A Texture atlas object, currently supports :

  • TexturePacker">www.codeandweb.com/texturepacker/} : through JSON export (standard and multipack texture atlas)
  • ShoeBox : through JSON export using the melonJS setting file
  • Standard (fixed cell size) spritesheet : through a {framewidth:xx, frameheight:xx, anchorPoint:me.Vector2d} object
Parameters:
Name Type Attributes Default Description
atlas Object | Array.<Object>

atlas information. See me.loader.getJSON

source HTMLImageElement | HTMLCanvasElement | String | Array.<HTMLImageElement> | Array.<HTMLCanvasElement> | Array.<String> <optional>
atlas.meta.image

Image source

cached Boolean <optional>
false

Use true to skip caching this Texture

Example
// create a texture atlas from a JSON Object
game.texture = new me.video.renderer.Texture(
    me.loader.getJSON("texture")
);

// create a texture atlas from a multipack JSON Object
game.texture = new me.video.renderer.Texture([
    me.loader.getJSON("texture-0"),
    me.loader.getJSON("texture-1"),
    me.loader.getJSON("texture-2")
]);

// create a texture atlas for a spritesheet with an anchorPoint in the center of each frame
game.texture = new me.video.renderer.Texture(
    {
        framewidth : 32,
        frameheight : 32,
        anchorPoint : new me.Vector2d(0.5, 0.5)
    },
    me.loader.getImage("spritesheet")
);

Extends

Methods

static createAnimationFromName(names, settingsopt) → {me.Sprite}

Create an animation object using the first region found using all specified names

Parameters:
Name Type Attributes Description
names Array.<String> | Array.<Number>

list of names for each sprite (when manually creating a Texture out of a spritesheet, only numeric values are authorized)

settings Object <optional>

Additional settings passed to the me.Sprite contructor

Returns:
me.Sprite
Example
// create a new texture object under the `game` namespace
game.texture = new me.video.renderer.Texture(
    me.loader.getJSON("texture"),
    me.loader.getImage("texture")
);

// create a new Sprite as renderable for the entity
this.renderable = game.texture.createAnimationFromName([
    "walk0001.png", "walk0002.png", "walk0003.png",
    "walk0004.png", "walk0005.png", "walk0006.png",
    "walk0007.png", "walk0008.png", "walk0009.png",
    "walk0010.png", "walk0011.png"
]);

// define an additional basic walking animation
this.renderable.addAnimation ("simple_walk", [0,2,1]);
// you can also use frame name to define your animation
this.renderable.addAnimation ("speed_walk", ["walk0007.png", "walk0008.png", "walk0009.png", "walk0010.png"]);
// set the default animation
this.renderable.setCurrentAnimation("simple_walk");
// set the renderable position to bottom center
this.anchorPoint.set(0.5, 1.0);

static createSpriteFromName(name, settingsopt) → {me.Sprite}

Create a sprite object using the first region found using the specified name

Parameters:
Name Type Attributes Description
name String

name of the sprite

settings Object <optional>

Additional settings passed to the me.Sprite contructor

Returns:
me.Sprite
Example
// create a new texture object under the `game` namespace
game.texture = new me.video.renderer.Texture(
   me.loader.getJSON("texture"),
   me.loader.getImage("texture")
);
...
...
// add the coin sprite as renderable for the entity
this.renderable = game.texture.createSpriteFromName("coin.png");
// set the renderable position to bottom center
this.anchorPoint.set(0.5, 1.0);

static getAtlas(nameopt) → {Object}

return the default or specified atlas dictionnary

Parameters:
Name Type Attributes Description
name String <optional>

atlas name in case of multipack textures

Returns:
Object

static getRegion(name, atlasopt) → {Object}

return a normalized region (or frame) information for the specified sprite name

Parameters:
Name Type Attributes Description
name String

name of the sprite

atlas String <optional>

name of a specific atlas where to search for the region

Returns:
Object

static getTexture(regionopt) → {HTMLImageElement|HTMLCanvasElement}

return the source texture for the given region (or default one if none specified)

Parameters:
Name Type Attributes Description
region Object <optional>

region name in case of multipack textures

Returns:
HTMLImageElement | HTMLCanvasElement

static getUVs(region) → {Float32Array}

return the uvs mapping for the given region

Parameters:
Name Type Description
region Object

region (or frame) name

Returns:
Float32Array -

region Uvs