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

6 years ago by BeachBum

I have 2 batches of Entities created that fight each other. Much of that is working but the method i'm currently using to select the next enemy does some crazy business sometimes.

I'm keeping track of all my entities in a 2D array and then sorting it by nearness every time an Entity is killed. The Entity that killed the last enemy then selects the top item off the array and heads for him. This is requiring some ugly array slicing and extra work to keep my array of the Entities updated. I think there must be methods within ImpactJS that can get me the next closest enemy or at least an updated list of Type A/B entities that are still around.

What would you suggest?


6 years ago by Joncom

Quote from BeachBum
there must be methods... that can get me the next closest enemy...

/* in player.js */
get_closest_enemy: function() {
    var closest_enemy;
    var enemies =;
    if(ememies.length > 0) {
        closest_enemy = ememies[0];
        for(var i=1; i<ememies.length; i++) {
            var enemy = enemies[i];
            if(this.distanceTo(enemy ) < this.distanceTo(closest_enemy)) {
                closest_enemy = enemy;
    return closest_enemy;

6 years ago by alexandre

BeachBum, out of curiosity, what is the maximum number of entities you may have onscreen at any one time?
Page 1 of 1
« first « previous next › last »