thrungames

Assets

Assets makes it easy and simple to load and initialize sprites (images) and audio files.

assets

Assets is a array of assets to load on game startup. There are two ways to load assets. An entry can be the url of the image/audio you want to load where the url is also going to be the index of your asset after the game is loaded. An entry can also be an object where you define the 'url' of the file, the 'index' you want it to be saved under. You can further extend the object with spritemap details, so it sets up the asset as a spritemap object. For this you need to define a 'spriteMap' object which contains a 'width' and a 'height'.

var game = new THRUNIUM.Game(400, 400);
// add assets as string
game.assets = ['images/sprite.png']; // add image to initialization queue
game.startState = 'menu';
game.backgroundColor = '#eee';

game.init();
game.start();

game.drawImage(game.assets['images/sprite.png'], 0, 0); // draw image
var game = new THRUNIUM.Game(400, 400);
// add asset as object
game.assets = [{
	url: 'images/sprite.png',
	index: 0
}]; // add image to initialization queue
game.startState = 'menu';
game.backgroundColor = '#eee';

game.init();
game.start();

game.drawImage(game.assets[0], 0, 0); // draw image
var game = new THRUNIUM.Game(400, 400);
// add asset as object and init it as spriteMap
game.assets = [{
	url: 'images/spritemap.png',
	index: 0,
	spriteMap: {
		width: 40,
		height: 40
	}
}]; // add image to initialization queue
game.startState = 'menu';
game.backgroundColor = '#eee';

game.init();
game.start();

game.assets[0].draw(game.ctx, 10, 10, 0); // draw the first image at (10, 10)
// spriteMap.draw(ctx, x, y, imgNum)