Class: Texture

me.CanvasRenderer. Texture

new Texture(atlas, texture, cached)

A Texture atlas object
For portability, a global reference to this class is available through the default renderer: me.video.renderer.Texture

Currently supports :
- TexturePacker : through JSON export
- 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 Argument Default Description
atlas Object atlas information. See me.loader.getJSON
texture Image <optional>
atlas.meta.image texture name
cached Boolean <optional>
false Use true to skip caching this Texture
Source:
texture.js, line 14
Example
// create a texture atlas from a JSON Object
texture = new me.video.renderer.Texture(
    me.loader.getJSON("texture"),
    me.loader.getImage("texture")
);

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

Extends

Classes

Error

Methods

<static> createAnimationFromName(names, settings) → {me.Sprite}

Create an animation object using the first region found using all specified names
Parameters:
Name Type Argument 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
Source:
texture.js, line 306
Returns:
Type
me.Sprite
Example
// create a new texture atlas 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, settings) → {me.Sprite}

Create a sprite object using the first region found using the specified name
Parameters:
Name Type Argument Description
name String name of the sprite
settings Object <optional>
Additional settings passed to the me.Sprite contructor
Source:
texture.js, line 273
Returns:
Type
me.Sprite
Example
// create a new texture atlas 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() → {Object}

return the Atlas dictionnary
Source:
texture.js, line 239
Returns:
Type
Object

<static> getRegion(name) → {Object}

return a normalized region/frame information for the specified sprite name
Parameters:
Name Type Description
name String name of the sprite
Source:
texture.js, line 261
Returns:
Type
Object

<static> getTexture() → {Image}

return the Atlas texture
Source:
texture.js, line 250
Returns:
Type
Image
Copyright © 2011 - 2017, Olivier Biot, Jason Oster, Aaron McLeod
Documentation generated by JSDoc 3.4.0 on 2017-02-28T11:37:40+08:00 using the DocStrap template modified by codename-.