1 decade ago by meckanism
Howdy impact ninjas,
I am trying to build my first game with impact, and decided to start it off by building a fog of war effect.
After browsing the forums i have found some people achieving such an effect using a simple grid of entity's and animating them according to the players distance.
Building upon those methods and extending them a little more i ended up with this effect http://www.mindsinfusion.com/gametest/ ( The trees are not being hidden by the fog, i'm yet to discover a way to do that using impact )
Anyways, i have a couple of concerns regarding the method i implemented.
I'm generating a lot of entities, the map is currently 128*128 with a tile size of 8, and i already need about 1025 entities to fill it.
Also, i was thinking of shrinking the fog tiles a bit to cut down on the blocky effect, but again, it would double my entity count. Should i be thinking about another approach to this effect ? or is there any way to optimize this?
I'm yet to run this on mobile, in my desktop i get 60 fps, unfortunately on a dual core laptop i'm already getting down to 30fps, so i guess on mobile this should be really slow.
I'd really appreciate your input in this, i'll drop my code below and hope any of you can help me gain some performance either by tweaking the code or giving me other ideias on how to approach this effect. Thanks in advance !
Code:
in my player entity init method i'm creating the grid to hold each fog block
then in the players update method
The fog entity
I am trying to build my first game with impact, and decided to start it off by building a fog of war effect.
After browsing the forums i have found some people achieving such an effect using a simple grid of entity's and animating them according to the players distance.
Building upon those methods and extending them a little more i ended up with this effect http://www.mindsinfusion.com/gametest/ ( The trees are not being hidden by the fog, i'm yet to discover a way to do that using impact )
Anyways, i have a couple of concerns regarding the method i implemented.
I'm generating a lot of entities, the map is currently 128*128 with a tile size of 8, and i already need about 1025 entities to fill it.
Also, i was thinking of shrinking the fog tiles a bit to cut down on the blocky effect, but again, it would double my entity count. Should i be thinking about another approach to this effect ? or is there any way to optimize this?
I'm yet to run this on mobile, in my desktop i get 60 fps, unfortunately on a dual core laptop i'm already getting down to 30fps, so i guess on mobile this should be really slow.
I'd really appreciate your input in this, i'll drop my code below and hope any of you can help me gain some performance either by tweaking the code or giving me other ideias on how to approach this effect. Thanks in advance !
Code:
in my player entity init method i'm creating the grid to hold each fog block
for( var i = 0; i < 32; i++ ){ for( var j = 0; j<32; j++ ){ var entity = ig.game.spawnEntity( EntityFog, 0 + i * 32, 0 + j * 32 ); this.fogMap.push( entity ); } }
then in the players update method
for( var n = 0; n < this.fogMap.length; n++ ) { // when the tiles are in range if( this.distanceTo( this.fogMap[n] ) <= this.fogRange ){ // if the tile has not been discovered yet, if( this.fogMap[n].currentAnim.alpha <= 1 && !this.fogMap[n].discovered) { // decrease alpha on tile until it hits .6 if( this.fogMap[n].currentAnim.alpha >= .6 ) { this.fogMap[n].currentAnim.alpha -= .04; } else { this.fogMap[n].discovered = true; } } else { // light the path around the player if( this.distanceTo( this.fogMap[n] ) <= this.fogRange/1.5 ){ // fade in the already discovered path in front of the player if( this.fogMap[n].currentAnim.alpha > .1) { this.fogMap[n].currentAnim.alpha -= .04; } } } } else { if( this.fogMap[n].discovered ) { // fadeout the already discovered tiles behind the player if( this.fogMap[n].currentAnim.alpha <= .6) { this.fogMap[n].currentAnim.alpha += .01; } } } }
The fog entity
EntityFog = ig.Entity.extend({ animSheet : new ig.AnimationSheet( 'media/fogTile.png', 32, 32 ), size : {x: 32, y: 32}, zIndex : 1000, init: function( x, y, settings ) { this.parent( x, y, settings ); this.addAnim( 'idle', 0.4, [0] ); this.discovered = false; }, update: function() { this.parent(); } });