This is something I do in flash quite often.
I need to get the enemy that ist nearest to the hero.
so I iterate through the enemy array and sort it.
in the end the nearest enemy is the first item in my array:
actionscript:
[as]
for(var i = 0; i < enemyArray.length; i++){
var enemy:Object = enemyArray[i]; // create a local object
// helper function that returns a distance value
enemy.theDistance = calcDist (hero, enemy)
// sort the array using the enemy object’s distance parameter
enemyArray.sortOn(“theDistance”, Array.NUMERIC);
}
[/as]
any idea how to port that to corona/LUA?
thanks in advance
-finefin
[import]uid: 70635 topic_id: 18973 reply_id: 318973[/import]
