2009-10-22 3 views
1

현재 AS3의 멋진 2D 게임 엔진에서 작업 중입니다. 다른 애니메이션의 XML을 통해 다른 플래시 무비 클립으로로드 할 수도 있습니다. 기능 중 하나를 사용하면 특정 동작을 수행 할 때 애니메이션을 넘길 수 있습니다. 그런 식으로 평소와 같이 좌우로 1 개의 애니메이션을 만들 수 있습니다. 올바르게 작동하는 행렬 변환이 있습니다. 그러나, 나는 앞뒤로 물건을 뒤집기위한 나의 논리가 잘못되었다고 생각한다. 결과적으로 잘못된 애니메이션이 잘못된 시간에 재생됩니다. 필자는 물리 요소가 관련되어 있기 때문에 키 누르기보다는 움직이는 물체의 속도를 기반으로 애니메이션을 재생하기로 결정했습니다. http://parrisstudios.com/Game_Design/gameEngineDemo/MovieClip을 뒤집기위한 결함있는 매트릭스

문제는 애니메이션이 잘못된 시간에 재생하거나 할 때 그들이해야 재생되지 않는 것이 주로 다음과 같습니다

은 현재 상태에서 게임에 대한 링크입니다.

여기 내 의견을 대변하는 코드입니다 (여러분이 생각하는 것을 알려주세요). 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 네가 두 번 튀기는 게 옳았 어! sooo 나는 그것을 바로 잡았다. 나는 어떤 클립이 뒤집혀 져야 하는지를 지정했는데, 현재 재생중인 것보다 문제를 해결하는 것으로 보인다! 이제 플립에는 무비 클립의 이름을 사용하는 매개 변수가 있으며 실제로 무언가가 될 수있는 현재 무비 클립이 아닌 해당 클립을 뒤집을 필요가 있는지 확인합니다. – Parris

+0

또한 업데이트 된 버전은 이제 같은 링크에 있습니다. 점핑 애니메이션은 꺼져 있었지만 플립 핑 논리가 주요 문제였습니다. 재생할 애니메이션을 결정할 때 문제가되지 않는 것 같습니다. – Parris

+0

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