Copy link to clipboard
Copied
I have some enemies(let say 10 enemies) on stage with the same instance names "enemy".
Each enemy have 4 hitpoints.
When a bullet hit a enemy the enemy remove from stage and a new enemy (enemy2) spawn on stage.
How can i do the spawn enemy to have let say 4 hitpoints?
Here is what i do for the enemies on stage to have 4 hitpoints.
var enemyArray:Array = new Array();
for (var e:int = numChildren - 1; e>= 0; e--)
{
var childe:DisplayObject = getChildAt(e);
if (childe.name == "enemy")
{
enemyArray.push(MovieClip(childe));
MovieClip(childe).hitpoints = 4;
}
}
Copy link to clipboard
Copied
1. they shouldn't have the same name.
2. assign whatever properties (like hitpoints) that you want (which you do in your last line of shown code).
3. because your code doesn't make sense, what are you trying to do? ie, do you want to have different enemies with different hitpoints?
Copy link to clipboard
Copied
This is for enemies that are already on stage with instance name .This enemies have this property(4 hitpoints)..
When i shot the enemy , a new enemy spawn.
That i am trying to do is, the new enemy to have they own properties(3 hitpoints).
Copy link to clipboard
Copied
I think i found what i must to do.
I just put hitpoints the time i create the new enemies .
var enemy1:Enemy = new Enemy;
enemy1Array.push(enemy1);
this.addChild(enemy1);
enemy1.hitpoints = 3;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now