2009-10-22 38 views
1

我目前正在研究AS3中的一個漂亮的小2D遊戲引擎。您甚至可以通過XML爲不同的動畫加載不同的Flash影片剪輯。其中一項功能還允許您在執行特定操作時翻轉動畫。這樣,你可以有左右兩個動畫(如往常一樣)。我有矩陣轉換正常工作;然而,我認爲我的邏輯來回翻轉事物是不正確的。結果是錯誤的動畫會在錯誤的時間播放。我決定根據移動物體的速度而不是按鍵來播放動畫,因爲我涉及到物理元素。錯誤的矩陣翻轉(鏡像反射)MovieClip

這裏是遊戲的鏈接在其當前狀態:http://parrisstudios.com/Game_Design/gameEngineDemo/

問題主要在於動畫在不正確的時間玩,還是不要當他們應該扮演。

這裏是我翻轉的代碼(讓我知道你們的想法): ps:方向變量是角色面對的最後方向(在這種情況下是左或右,稍後會在代碼中進行描述)

private function drawJumpMode():void { 
     var change:Boolean = false; 
     //decide whether to swap graphics or continue playing 

     if (Math.abs(particleGroup.particles[0].velocity.y) < epsilon && Math.abs(particleGroup.particles[0].velocity.x) < epsilon && direction == "right") { 
      if (lastClipAction != "stillRight"){ 
       lastClipAction = "stillRight"; 
       change = true; 
      } 
     } 
     else if (Math.abs(particleGroup.particles[0].velocity.y) < epsilon && Math.abs(particleGroup.particles[0].velocity.x) < epsilon && direction == "left") { 
      if (lastClipAction != "stillLeft"){ 
       lastClipAction = "stillLeft"; 
       change = true; 
      } 
     } 
     else if (particleGroup.particles[0].velocity.y > 0 && Math.abs(particleGroup.particles[0].velocity.x) < epsilon) { 
      if (lastClipAction != "down"){ 
       lastClipAction = "down"; 
       change = true; 
      } 
     } 
     else if (particleGroup.particles[0].velocity.y < 0 && Math.abs(particleGroup.particles[0].velocity.x) < epsilon) { 
      if (lastClipAction != "up"){ 
       lastClipAction = "up"; 
       change = true; 
      } 
     } 
     else if (particleGroup.particles[0].velocity.x > 0) { 
      if (lastClipAction != "right") { 
       lastClipAction = "right"; 
       direction = "right"; 
       change = true;    
      } 
     } 
     else if (particleGroup.particles[0].velocity.x < 0) { 
      if (lastClipAction != "left"){ 
       lastClipAction = "left"; 
       direction = "left"; 
       change = true; 
      } 
     } 

     //If the movie clip has changed, swap the old one back into the all clips library and get the new one. 
     if (change) { 
      //set flip to false whenever there is a change in movie clip 
      flipped = false; 
      //if the movie clip was flipped before, this should flip it 
          //back to normal 
      flip(); 
          //remove movie clip from the scene 
      game.removeChild(playingMovieClip); 
          //check it back into the movie clip library 
      allClips.addChild(playingMovieClip); 
          //add the movie clip into the scene 
      playingMovieClip = MovieClip(allClips.getChildByName(actionToClip[lastClipAction + "Name"])); 
      game.addChild(playingMovieClip); 
     } 

     //Flip if needed 
     flip(); 

     //set it to true so that it won't be constantly flipped. 
     flipped = true; 

     //set movie clip to be center over the main particle 
     playingMovieClip.x = particleGroup.particles[0].center.x; 
     playingMovieClip.y = particleGroup.particles[0].center.y; 
    } 
private function flip():void { 
     //If a transformation is required, then do so 
     if (actionToClip[lastClipAction + "H"]=="1" && !flipped){ 
      flipHorizontal(playingMovieClip); 
     } 
     if (actionToClip[lastClipAction + "V"]=="1" && !flipped){ 
      flipVertical(playingMovieClip); 
     } 
    } 
+1

什麼問題?你期望看到什麼,而你看到了什麼?儘量做到儘可能具體。 – Amber

+0

是的,我想這是不清楚。我除了看到所有動畫的玩法完全如我所料。這裏是一個鏈接:http://parrisstudios.com/Game_Design/gameEngineDemo/ 本質上有時圖片翻轉回來,當他們不應該或某些動畫時,他們應該觸發。 – Parris

回答

1

我相信有問題的代碼在這裏。

  //If the movie clip has changed, swap the old one back into the all clips library and get the new one. 
      if (change) { 
        //set flip to false whenever there is a change in movie clip 
        flipped = false; 
        //if the movie clip was flipped before, this should flip it 
         //back to normal 
        flip(); 
         //remove movie clip from the scene 
        game.removeChild(playingMovieClip); 
         //check it back into the movie clip library 
        allClips.addChild(playingMovieClip); 
         //add the movie clip into the scene 
        playingMovieClip = MovieClip(allClips.getChildByName(actionToClip[lastClipAction + "Name"])); 
        game.addChild(playingMovieClip); 
      } 

      //Flip if needed 
      flip(); 

問題是,你正在這裏做一個雙重翻轉。如果您實際上正在從更改中更改剪輯,則可以發現該功能。例如,如果你從右跑到右站。從右跑到左跑時出現問題。由於它們是剛剛翻轉的相同剪輯,因此在這種情況下最終會做兩次翻轉。這會導致moonwalk行爲:-)。

我會建議清理這個邏輯並提供一種方法來重置翻轉。而不是翻回原來的方向,重新回到它,所以你可以保證剪輯的狀態。

+0

WOOO是啊,你是對的雙翻!所以我糾正了它。我指定應該翻轉哪個剪輯而不是當前播放的剪輯,這似乎解決了問題!因此,現在翻轉了一個參數,它取得了影片剪輯的名稱,它將檢查該剪輯是否需要翻轉,而不是當前的影片剪輯,它可能是任何東西。 – Parris

+0

此外,更新後的版本現在處於相同的鏈接。跳躍動畫已關閉,但翻轉邏輯是主要問題。決定播放什麼動畫似乎不成問題。 – Parris

+0

http://parrisstudios.com/Game_Design/gameEngineDemo/bin/ – Parris