Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Swapping Z-Indexes of Entities in Impact JS

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 365
    Comment on it

    Impact JS keeps all entities in an array in the order of their creation.

    The main problem is that it is also the order of their z indexes. So the entity at the last index of array is at the top of every other entity. But in our games we get some situations where we want some entity above other irrespective of their place in the array.

    For that I have written a piece of code that will allow you to change that array and as soon as that array is changed automatically the entity's place on another.

    I have a few situations where I want to put one entity in front of another, but don't want to modify the z index directly and sort, etc. So I created this snippet.

    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;
    }});
    



    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);
    

    Hope it Helps.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: