Reputation: 1
So I know how to target a specific instance using MovieClip(root).objectName which I think is nasty way of referring to it anyways, but right now I'm trying to make a fighting stick-figure game and I can only refer my code to one NPC right now using an "enemy" class but I would like it if I could spawn multiple NPC's at once using the enemy class and instead target the enemy class instead of the instance itself while still having the NPC instances being unique so when I hit one they don't all get hit.
Upvotes: 0
Views: 620
Reputation: 1593
create an array for your enemy class, like this:
NPCArray = [];
for ( var i = 0; i < 10; i++)
{
var npc:NPC = new NPC();
NPCArray.push(npc);
this.addChild(npc);
}
then when you want to update them all:
for ( var i = 0; i < NPCArray.length; i++)
{
var npc:NPC = NPCArray[i];
npc.update()
}
I would recommend reading this tutorial, that explains the basis of AS3 game development. http://gamedev.michaeljameswilliams.com/2008/09/17/avoider-game-tutorial-1/
Upvotes: 1