XNA/MonoGame을 사용하여 게임을하고 있는데 버그가 있습니다.MonoGame - 다른 클래스에서 동일한 함수를 호출하면 다른 동작이 발생합니다.
스프레이 시트를 사용하여 매우 간단한 애니메이션을 보여주는이 기능은 Expload입니다.
- 그 기능에서 만들어진 클래스, 화살표
- 다른 클래스, 그 통화 currentArrow.Explode라고 (와 잘 작동) :
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 개 클래스에서이 함수를 호출 OnCollsionEvents
여기는 diff에서 함수를 호출하는 방법입니다. 서로 다른 클래스 : 클래스 나에게 문제/버그주는 화살표 (에 :
클래스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는) 클래스 총에 (호출되는 경우
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이며 애니메이션이 올바르게 시작됩니다.
화살표에서 Exploade를 호출하고 업데이트를 시작하면 정수 값은 16이며 애니메이션을 시작하지 않습니다.
다른 클래스에서 같은 함수를 호출하고 생성 된 동일한 클래스에서 함수를 업데이트하는 것이 가능한지 이해할 수 없으며 다른 결과를 얻습니다.
- 나는 무엇을 놓쳤을까요?
- 또는 어디에서보아야합니까?
- 이런 종류의 것을 테스트하는 좋은 방법은 무엇입니까?