这与我提出的最后一个问题有关,虽然音频问题已得到解决,但我仍然无法更换敌人的精灵表。
应该发生的事情是,当敌人进入玩家范围时,他们的精灵表将从“中立”变为“敌对”,我有一些代码到目前为止 - 我会发布 - 但是我我不确定从哪里开始。更改精灵表的实际功能是在计时器内,而该功能在'敌人'类中。
我声明并将图像设置在实际的敌人类中,而不是形式,如果这有任何区别的话。
这是我到目前为止的代码:
public void ChangeSpriteSheet()
{
if (Hostile)
{
enemySprite = Properties.Resources.WormSheet; //'Hostile' sprite sheet
CurrentPosition.seen = true;
}
else
{
enemySprite = Properties.Resources.WormSheetNeutral;
}
}
计时器:
//The timer to generate random numbers, is slower so that the enemy can complete it's move before picking a new direction
private void wander_Tick(object sender, EventArgs e)
{
CurrentPosition.seen = false;
int count = 0;
foreach (Enemies en in enemyList)
{
en.ChangeSpriteSheet(); //Changes the sprite sheet of the enemy
en.Direction(); //Determines the direction of the enemy when wandering
count++;
}
//This foreach loop will play audio when any of the enemies sees the player
if (CurrentPosition.seen)
{
wplayer.controls.play();//Plays music when player is in view
}
else
{
wplayer.controls.stop();//Stops the music
}
}
任何帮助都会一如既往地受到赞赏:)