Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Ant101

I have one more question regarding background tiles. From what I can see in the documentation, background tile resources are specified by an xy offest on a single tilesheet resource. I need to be able to sepcify the resource for each background tile independantly, as I will not have them available statically as a tilesheet. I reliase that this will have performance implications, but is this possible in Impact?

Thank you

1 decade ago by dominic

You can of course write some code that does this. Subclass the ig.BackgroundMap class, overwrite the draw method, change the line that draw's each tile and feed it an array of ig.Images instead of a tilesheet:

ig.ImageMap = ig.BackgroundMap.extend({
	
	setTileset: function( tileset ) {
		this.tileset = tileset;
	},
	
	draw: function() {
		/* ... same as in ig.BackgroundMap */
		
		// Change this line:
		// this.tiles.drawTile( pxX, pxY, tile-1, this.tilesize );
		// to:
		this.tileset[tile-1].draw( pxX, pxY );
		
		/* same as in ig.BackgroundMap .. */
	}
});


var data = [
    [1,2,3],
    [0,3,2],
    [2,0,1],
];
var tiles = [
	new ig.Image( 'media/tiles1.png' ),
	new ig.Image( 'media/tiles2.png' ),
	new ig.Image( 'media/tiles3.png' )
];
var map = new ig.ImageMap( 16, data, tiles );

(untested)

As you already said, this may have some performance implications. Especially loading will take a bit longer, because each HTTP request for the tiles has some overhead.
Page 1 of 1
« first « previous next › last »