大学の学期 1 の宿題として、単純な XNA ゲームを開発しています。ただし、敵のスプライトの描画ループで少し壁にぶつかりました。私が知る限り、敵のスプライトはすべて game1.cs クラスのリストに追加されていますが、リストの最初のスプライトのみが描画されています。
このメソッドは、敵のインスタンスをリストに追加します。Spawn は update メソッドで 1 秒ごとにインクリメントされます。これにより、敵が 4 体出現するまで毎秒順番に出現します。
public void LoadEnemies()
{
int randX = rand.Next(0, 1000);
int randY = rand.Next(0, 500);
if (spawn >= 1)
{
spawn = 0;
if (enemyList.Count() < 4)
{
enemyList.Add(new NM_Enemy(Content.Load<Texture2D>("Wisp1"), new Vector2(randX, randY)));
enemyList.Add(new NM_Enemy(Content.Load<Texture2D>("Wisp2"), new Vector2(randX, randY)));
enemyList.Add(new NM_Enemy(Content.Load<Texture2D>("Wisp3"), new Vector2(randX, randY)));
enemyList.Add(new NM_Enemy(Content.Load<Texture2D>("Wisp4"), new Vector2(randX, randY)));
}
}
//Checks if enemies in the list have left the level bounds
for (int i = 0; i < enemyList.Count; i++)
{
if (!enemyList[i].isVisible)
{
enemyList.RemoveAt(i);
i--;
}
}
}
Draw メソッド
foreach (NM_Enemy enemy in enemyList)
{
enemy.Draw(gameTime, spriteBatch);
}
Update メソッド
foreach (NM_Enemy enemy in enemyList)
{
enemy.Update(gameTime);
}