2014-11-05 24 views
0

我正在使用XNA/MonoGame進行遊戲,並且遇到了一個錯誤。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班這個功能:

  • 該功能是在製造,A級,被稱爲
  • 不同的類,該呼叫currentArrow.Explode(和做工精細)叫做OnCollsionEvents

這裏是我如何調用差異函數erent類: 在類箭(這讓我有問題/錯誤:

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,並正確啓動動畫。

當我撥打箭頭並開始更新時,整數值是16,它不啓動動畫。

我不明白的是,它如何從不同的類調用相同的函數,並在創建它的同一類中更新該函數,並獲得不同的結果。

  • 我錯過了什麼?
  • 或我應該在哪裏尋找?
  • 什麼是測試這種東西的好方法?

回答

1

我發現我的問題。

當箭頭到達屏幕的頂部時,它不停地爆炸。 所以我只是添加另一個if語句,來檢查是否沒有爆炸動畫allrdy運行。

相關問題