我正在使用XNA / MonoGame开发游戏,但遇到了错误。
我有这个功能Expload,它使用精灵表显示了一个非常简单的动画。
public void Exploade(Rectangle explosionRect)
{
ex = new ExpolsionAnimation(content, "Explsion4", explosionRect,
_frameWaiteTime:50,
_frameWidth:90 , _frameHeight: 45,
_rows: 4 , _culloms: 3,
_rotation: 0
);
playAnimation = true;
}
我从2个类中调用此函数:
这是我在不同类中调用函数的方式:在Arrow类中(这给了我问题/错误:
public override void Update(GameTime gt)
{
if (!MonsterHit)
{
this.location.Y -= movmentSpeed;
}
//when the arrow touch the top of the window, it need to expload, but for some reason when i start the animation here, it just doesn't work.
if (ReachedTheTop)
this.Exploade(new Rectangle(location.X - 10, 1, 30, 30));
//here i start updating the animation
if (playAnimation)
ex.Update(gt);
base.Update(gt);
}
在OnCollsionEvents类中
public void Update(SpaceShip _spaceShip, Monsters _monsters)
{
List<Arrow> gameArrows = player.Gun.ArrowList;
if (MonsterCount > 0)
{
foreach (var monster in monsters.MonstersList)
{
if (monster.ReachedTheButtom)
{
MonsterHitTheFloor = true;
}
if (monster.CollsionWith(player))
{
MonsterHitTheSpaceship = true;
}
foreach (var currentArrow in gameArrows)
{
if (currentArrow.CollsionWith(monster))
{
currentArrow.MonsterHit = true;
currentArrow.Exploade(new Rectangle(monster.Location.X, monster.Location.Y, monster.AreaRect.Width, monster.AreaRect.Height));
monster.GotHit = true;
}
}
}
}
这是Arrow.Update的调用位置(在Gun类中)
public override void Update(GameTime gt)
{
if (arrowsNotEmpty)
{
for (int i = 0; i < ArrowList.Count; i++)
{
ArrowList[i].Update(gt);
//because of the bug, i cant even remove an arrow afther it reach the top of the window
//because the animation is not Ended.
if ((ArrowList[i].IsOverTheTop || ArrowList[i].MonsterHit) && ArrowList[i].AnimationEnded)
ArrowList.RemoveAt(i);
}
}
}
现在我遇到的问题是这样的。在动画类中,我有一个整数,可以通过毫秒,因此我可以创建一种计时器来运行动画。当我调用函数Exploade并开始更新OnCollsionEvents类中的动画时,整数值为64并正确启动动画。
当我从Arrow调用Exploade并开始更新时,整数值为16,这不会启动动画。
我不明白的是,如何可能从不同的类调用相同的函数,并在创建的同一类中更新该函数,并获得不同的结果。
我发现了我的问题。
当箭头到达屏幕顶部时,它不断爆炸。所以我只添加另一个if语句,以检查是否没有爆炸动画特效运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句