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 yatayata

is there an easy way to find the size of the level in pixels?

i have a convoluted method like below... but seems there must be an easier way. also the maps could be different sizes, and this is not guaranteed that layer X is the largest level...


var sampleMap = ig.game.backgroundMaps[1]; 
var tilesize = sampleMap.tilesize;
pk.maxWidth  = sampleMap.width * tilesize;
pk.maxHeight = sampleMap.height * tilesize;
console.log("mapSize:" + pk.maxWidth + ", " + pk.maxHeight);

1 decade ago by fugufish

i'm using the same method! would be cool if we can find a simplified method

1 decade ago by dominic

Usually your CollisionMap is as big as your whole level, so you could use ig.game.collisionMap to compute the size. This of course depends on your game and whether you even have a collision map.

Otherwise your way of computing the map size is just fine. Of course you could put it into a function, or write a small plugin that injects this into all Map classes:

ig.module( 
	'plugins.map-size' 
)
.requires(
	'impact.map'
)
.defines(function(){

ig.Map.inject({
	init: function( tilesize, data ) {
		this.parent( tilesize, data );
		this.pxWidth = this.width * tilesize;
		this.pxHeight = this.height * tilesize;
	}
});

});

Put this into lib/plugins/map-size and require the plugins.map-size module. You can then use ig.game.collisionMap.pxWidth and ig.game.collisionMap.pxHeight (or ig.game.backgroundMaps[0].pxWidth ...).

1 decade ago by fugufish

@dominic works like a charm

1 decade ago by yatayata

this is awesome, thanks very much! its also a nice tutorial on how to build an impact plugin AND ways to add methods to javascript objects. nice protip :)

the only gotcha is that the collision map has to be full-size, which it usually is.

1 decade ago by JoshuaSullivan

This was very helpful. Thanks for the quick plugin dominic!
Page 1 of 1
« first « previous next › last »