0
爲我在大學期間的第1學期任務開發一個簡單的XNA遊戲。不過,我已經爲敵方精靈繪製了一圈牆。據我所知,所有敵方精靈都被添加到game1.cs類的列表中,但只有列表中的第一個被繪製。XNA循環繪製多個子畫面不工作
此方法將敵人的實例添加到列表中。更新方法中,每秒產卵數正在增加。這會使敵人每秒產生一次,直到四次產卵。
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);
}
更新方法
foreach (NM_Enemy enemy in enemyList)
{
enemy.Update(gameTime);
}
我會做什麼:使用調試器。我想你正在使用Visual Studio,對吧?雙擊該行的左側以設置中斷點。我會在你的繪製方法中這樣做,這樣你就可以看到列表中的內容以及在特定時刻繪製哪一個。要開始調試,點擊F5(或頂部的調試按鈕)。 –