gamvas.Resource

Description

Class for resource handling, aka loading images and other game data

Constructor

new gamvas.Resource();

Summary
gamvas.ResourceClass for resource handling, aka loading images and other game data
Functions
getImageLoad a image from url
getSoundLoad a sound/music file from url
statusGet the status of all loading resources
doneAre all resources loaded?

Functions

getImage

gamvas.Resource.prototype.getImage = function(url)

Description

Load a image from url

Parameters

urlThe image url

Returns

A javascript image object, that might be not fully loaded yet

Example

myState = gamvas.State.extend({
    init: function() {
        this.img = this.resource.getImage('myImage.png');
    },
    draw: function(t) {
        if (this.resource.done()) { // everything loaded?
            // do something with this.img
        } else { // data is still loading
            // print current loading status in percent
            this.c.fillText("Loading... "+(100*this.resource.status())+"%", 10, 10);
        }
    }
});

getSound

gamvas.Resource.prototype.getSound = function(url)

Description

Load a sound/music file from url

Parameters

urlThe audio file url

Returns

A javascript Audio object, that might be not fully loaded yet

Example

myState = gamvas.State.extend({
    create: function(name) {
        this._super(name);
        this.snd = this.resource.getSound('pling.wav');
    },
    draw: function(t) {
        if (this.resource.done()) { // everything loaded?
             // play the sound
             gamvas.sound.play(this.snd);
        } else { // data is still loading
            // print current loading status in percent
            this.c.fillText("Loading... "+(100*this.resource.status())+"%", 10, 10);
        }
    }
});

status

gamvas.Resource.prototype.status = function()

Description

Get the status of all loading resources

Returns

A value between 0 and 1 depending on how much of the resources are loaded

See

gamvas.Resource.getImage

done

gamvas.Resource.prototype.done = function()

Description

Are all resources loaded?

Returns

true or false

See

gamvas.Resource.getImage

gamvas.Resource.prototype.getImage = function(url)
Load a image from url
gamvas.Resource.prototype.getSound = function(url)
Load a sound/music file from url
gamvas.Resource.prototype.status = function()
Get the status of all loading resources
gamvas.Resource.prototype.done = function()
Are all resources loaded?
Close