Skip to content

mattdesl/kami-assets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kami-assets

experimental

This overrides assetloader to provide some kami-specific features. The return type for images are kami-texture objects.

This asset loader expects a GL context (or a kami-context). If the provided context is a kami-context with handleContextLoss, assets will be invalidated upon context restore, which will froce a re-run of the preloader.

usage

NPM

Typical usage with a render loop could look like this:

//create a canvas..
var gl = require('kami-context')({
	width: 250,
	height: 250
});

document.body.appendChild(gl.canvas);

//create a new asset loader
var assets = require('kami-assets')(gl);

//the returned objects are kami-textures
var tex1 = assets.add("img/scene.png");
var tex2 = assets.add("img/grass.png");

//so we can operate on them like so:
tex1.setFilter(Texture.Filter.LINEAR);

function update() {
    requestAnimationFrame(update);

    //tick forward to the next asset in the preloader
    if (assets.update()) {
    	//returns true when all assets are loaded,
        //render your game..
    } else {
        //game is loading.. show a preloader
    }
}

requestAnimationFrame(update);

License

MIT.

About

Kami-specific asset loader

Resources

Stars

Watchers

Forks

Packages

No packages published