Namespace: loader

me. loader

a small class to manage loading of stuff and manage resources There is no constructor function for me.input.
Source:
loader.js, line 8

Classes

Error

Members

<static> crossOrigin :String

crossOrigin attribute to configure the CORS requests for Image data element.
By default (that is, when the attribute is not specified), CORS is not used at all.
The "anonymous" keyword means that there will be no exchange of user credentials via cookies,
client-side SSL certificates or HTTP authentication as described in the Terminology section of the CORS specification.
Type:
  • String
Source:
loader.js, line 285
See:
Example
// allow for cross-origin texture loading in WebGL
me.loader.crossOrigin = "anonymous";

// set all ressources to be loaded
me.loader.preload(game.resources, this.loaded.bind(this));

Methods

<static> getBinary(name) → {Object}

return the specified Binary object
Parameters:
Name Type Description
name String of the binary object ("ymTrack");
Source:
loader.js, line 640
Returns:
Type
Object

<static> getImage(Image) → {Image}

return the specified Image Object
Parameters:
Name Type Description
Image String name of the Image element ("tileset-platformer");
Source:
loader.js, line 662
Returns:
Type
Image

<static> getJSON(Name) → {Object}

return the specified JSON Object
Parameters:
Name Type Description
Name String for the json file to load
Source:
loader.js, line 685
Returns:
Type
Object

<static> getLoadProgress() → {Number}

Return the loading progress in percent
Deprecated:
  • use callback instead
Source:
loader.js, line 705
Returns:
Type
Number

<static> getTMX(tmx) → {XML|Object}

return the specified TMX/TSX object
Parameters:
Name Type Description
tmx String name of the tmx/tsx element ("map1");
Source:
loader.js, line 619
Returns:
Type
XML | Object

<static> load(resource, onload, onerror)

Load a single resource (to be used if you need to load additional resource during the game)
Parameters:
Name Type Description
resource Object
Properties
Name Type Argument Description
name String internal name of the resource
type String "audio", binary", "image", "json", "tmx", "tsx"
src String path and/or file name of the resource (for audio assets only the path is required)
stream Boolean <optional>
set to true if you don't have to wait for the audio file to be fully downloaded
onload function function to be called when the resource is loaded
onerror function function to be called in case of error
Source:
loader.js, line 446
Example
// load an image asset
me.loader.load({name: "avatar",  type:"image",  src: "data/avatar.png"}, this.onload.bind(this), this.onerror.bind(this));

// start loading music
me.loader.load({
    name   : "bgmusic",
    type   : "audio",
    src    : "data/audio/"
}, function () {
    me.audio.play("bgmusic");
});

<static> onload()

onload callback
Source:
loader.js, line 258
Example
// set a callback when everything is loaded
me.loader.onload = this.loaded.bind(this);

<static> onProgress()

onProgress callback
each time a resource is loaded, the loader will fire the specified function, giving the actual progress [0 ... 1], as argument, and an object describing the resource loaded
Source:
loader.js, line 270
Example
// set a callback for progress notification
me.loader.onProgress = this.updateProgress.bind(this);

<static> preload(resources, onload, switchToLoadState)

set all the specified game resources to be preloaded.
Parameters:
Name Type Argument Default Description
resources Array.<Object>
Properties
Name Type Argument Description
name String internal name of the resource
type String "audio", binary", "image", "json", "tmx", "tsx"
src String path and/or file name of the resource (for audio assets only the path is required)
stream Boolean <optional>
set to true if you don't have to wait for the audio file to be fully downloaded
onload function <optional>
me.loader.onload function to be called when all resources are loaded
switchToLoadState boolean <optional>
true automatically switch to the loading screen
Source:
loader.js, line 385
Example
game_resources = [
  // PNG tileset
  {name: "tileset-platformer", type: "image",  src: "data/map/tileset.png"},
  // PNG packed texture
  {name: "texture", type:"image", src: "data/gfx/texture.png"}
  // TSX file
  {name: "meta_tiles", type: "tsx", src: "data/map/meta_tiles.tsx"},
  // TMX level (XML & JSON)
  {name: "map1", type: "tmx", src: "data/map/map1.json"},
  {name: "map2", type: "tmx", src: "data/map/map2.tmx"},
  {name: "map3", type: "tmx", format: "json", data: {"height":15,"layers":[...],"tilewidth":32,"version":1,"width":20}},
  {name: "map4", type: "tmx", format: "xml", data: {xml representation of tmx}},
  // audio resources
  {name: "bgmusic", type: "audio",  src: "data/audio/"},
  {name: "cling",   type: "audio",  src: "data/audio/"},
  // binary file
  {name: "ymTrack", type: "binary", src: "data/audio/main.ym"},
  // JSON file (used for texturePacker)
  {name: "texture", type: "json", src: "data/gfx/texture.json"}
];
...
// set all resources to be loaded
me.loader.preload(game.resources, this.loaded.bind(this));

<static> setBaseURL(type, url)

change the default baseURL for the given asset type.
(this will prepend the asset URL and must finish with a '/')
Parameters:
Name Type Argument Default Description
type String "*", "audio", binary", "image", "json", "tmx", "tsx"
url String <optional>
"./" default base URL
Source:
loader.js, line 355
Example
// change the base URL relative address
me.loader.setBaseURL("audio", "data/audio/");
// change the base URL absolute address for all object types
me.loader.setBaseURL("*", "http://myurl.com/")

<static> unload(resource) → {Boolean}

unload specified resource to free memory
Parameters:
Name Type Description
resource Object
Source:
loader.js, line 507
Returns:
true if unloaded
Type
Boolean
Example
me.loader.unload({name: "avatar",  type:"image",  src: "data/avatar.png"});

<static> unloadAll()

unload all resources to free memory
Source:
loader.js, line 564
Example
me.loader.unloadAll();
Copyright © 2011 - 2017, Olivier Biot, Jason Oster, Aaron McLeod
Documentation generated by JSDoc 3.4.0 on 2017-02-28T11:37:41+08:00 using the DocStrap template modified by codename-.