質問

I'm making a First Person Shooter game in flash AS3. I'm still learning AS3 and need help. I have a movieclip 'Player' thats placed on the stage at the start, it can shoot and move so far, but I need enemies for the player to shoot at.

I have created an enemy and need help getting multiple instances of the same movieclip (the enemy) to spawn off stage and movie towards the 'Player' movieclip. I believe I need to create an array to get 2 or more of the same movieclip on that stage at any one point in time but I'm completely stuck on how to do this.

Thanks in advanced.

Links to my code are Here (Please note 'Baddy.as' I know is spelt wrong and also it's now been changed to 'Enemy.as')

役に立ちましたか?

解決

Once you have your Enemy class you can just create multiple instances of it and store them in an array.

var enemies:Array =  [];
var enemy:Enemy = new Enemy();
stage.addChild(enemy);
enemies.push(enemy);

Then you can loop through the enemies and move them using the enemies array.

for(var i=0; i<enemies.length; ++i)
{
    move(enemies[i]);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top