1 decade ago by MikeL
//Inject a new function into ig.Game which allows entities to swap //their indexes (actual place number within the ig.game.entities array //as opposed to the zIndex value - which may be different), //so as to draw one entity "in front" of another. ig.Game.inject({ swapzIndex: function( entityA, entityB ) { x = this.entities.indexOf(entityA); y = this.entities.indexOf(entityB); this.entities[y] = entityA; this.entities[x] = entityB; } });
I have a few situations where I want to put one entity in front of another, but don't won't to modify the z index directly and sort, etc. So I created this snippet.
It didn't seem to justify a whole plugin (though you could do that), instead I just insert it into the init function of my main.js file. You can then use it as in:
ig.game.swapzIndex(entityA, entityB);