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

1 decade ago by MikeL

//Inject a new function into ig.Game which allows entities to swap
//their indexes (actual place number within the array
//as opposed to the zIndex value - which may be different), 
//so as to draw one entity "in front" of another.
    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:, entityB);

1 decade ago by fugufish

awesome code thx!

1 decade ago by MikeL

Thanks. Forget to mention that you need to use Impact 1.17 or above because it's got that great new inject function. Also it's probably best to call this function only after your entities have been updated in the main game loop to avoid unexpected results. :)

1 decade ago by MikeL

If you're looking at the RSS feed, get the code directly from the forum instead. Had to modify it a bit. Got a little too excited about the inject function and put the code up too fast without fully testing it. Let me know if you you have any problems with it.
Page 1 of 1
« first « previous next › last »