2013-08-14 4 views
-1

나는 이길 게임을 만들고 지금 당장 내 캐릭터를 걷고 뛰어 내리고있다. 지금까지 3 번의 공격 애니메이션이 있었는데 막 작동합니다. 이것은 내가 달성하려고하는 것입니다. 플레이어가 공격 버튼을 누른 다음 캐릭터가 공격하고 플레이어가 공격 버튼을 계속 누르고 있으면 공격/펀칭 시퀀스가 ​​계속되거나 다른 공격 키가 눌러 진 경우입니다. 스위치 공격/발 차기 애니메이션 (참고 : 플레이어가 키를 누르고 있으면 키를 눌러야합니다.)내 캐릭터 싸움 만들기

또한 현재 공격 애니메이션이 현재 공격 애니메이션의 다음 프레임으로 이동하는 대신 현재 공격 애니메이션이 완전히 끝나면 어떻게하면 다음 공격 애니메이션으로 갈 수 있습니까? 캐릭터가 공격을하고 공격 키를 누르면 캐릭터는 현재의 공격 애니메이션을 끝내고 다음 공격 애니메이션 프레임으로 이동합니다. 그렇지 않으면 중지됩니다. 배열을 만들거나 클래스를 확장해야하는 이유는 무엇입니까? 나는 이런 식으로 내가 발견 사본을 게임을 만들려고하지만, AS2에

https://www.dropbox.com/s/zhf68zmi0ktmeqq/DD%20%282%29.zip

이 내가 지금까지 한 일 자사의

당신이 시도조차 시도하지 않은 것 같습니다
package 
{ 
    import flash.display.MovieClip; 
    import flash.events.Event; 
    import flash.events.KeyboardEvent; 
    import flash.ui.Keyboard; 
    import flash.utils.*; 
    import com.greensock.TweenLite; 
    import com.greensock.easing.*; 
    import com.greensock.plugins.*; 

    public class Player extends MovieClip 
    { 
     TweenPlugin.activate([BlurFilterPlugin]); 
     //Player run speed setting; 
     var RunSpeed:Number = 8; 
     //Player key presses 
     var RightKeyPress:Boolean = false; 
     var LeftKeyPress:Boolean = false; 
     var UpKeyPress:Boolean = false; 
     //Jump variables 
     var Gravity:Number = 1.5; 
     var JumpPower:Number = 0; 
     var CanJump:Boolean = false; 
     var Jumped:Boolean = false; 
     //Dash variable 
     var Pressed:Boolean = false; 
     var LastKeyPressed:Number = -1; 
     var DashAmount:Number = 250; 
     var DoubleTapDelay:Number = 260;//-- delay in milliseconds 
     var Dashing:Boolean = false; 
     var RightDash:Boolean = false; 
     var LeftDash:Boolean = false; 

     public function Player() 
     { 
      stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyDown); 
      stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed); 
      addEventListener(Event.ENTER_FRAME,Update); 
     } 

     function KeyDown(event:KeyboardEvent) 
     { 
      stage.removeEventListener(KeyboardEvent.KEY_DOWN, SecondDash); 
      //If key is down cannot dash 
      RightDash = false; 
      LeftDash = false; 

      //When Key is Down 
      if (event.keyCode == 39) 
      { 
       RightKeyPress = true; 
      } 

      if (event.keyCode == 37) 
      { 
       LeftKeyPress = true; 
      } 

      if (event.keyCode == 38) 
      { 
       UpKeyPress = true; 
      } 
     } 

     function KeyPressed(event:KeyboardEvent):void 
     { 
      stage.removeEventListener(KeyboardEvent.KEY_DOWN, KeyPressed); 
      stage.addEventListener(KeyboardEvent.KEY_UP, KeyUp); 

      //If on floor 
      if (CanJump) 
      { 
       //If right key is down 
       if (event.keyCode == 39) 
       { 
        if (event.keyCode == 39 && Pressed) 
        { 
         //If right key press matches with recent right key press, dash right 
         Dashing = true; 
         RightDash = true; 
        } 
        Pressed = true; 
        setTimeout(function(){Pressed = false}, DoubleTapDelay); 
       } 

       if (event.keyCode == 37) 
       { 
        if (event.keyCode == 37 && Pressed) 
        { 
         //If left key press matches with recent left key press, dash left 
         Dashing = true; 
         LeftDash = true; 
        } 
        Pressed = true; 
        setTimeout(function(){Pressed = false}, DoubleTapDelay); 
       } 

      } 
     } 



     function Update(event:Event) 
     { 

      //Adding gravity to the game world 
      JumpPower += Gravity; 
      //if player is more than 300 on the y-axis 
      if (this.y > 300) 
      { 
       //Player stays on the ground and can jump 
       JumpPower = 0; 
       CanJump = true; 
      } 


       //If already jumped and on floor 
       if (Jumped == true && CanJump) 
       { 
        //Cannot jump again 
        CanJump = false; 

        //If on floor and right key is pressed run right 
        if ((RightKeyPress)) 
        { 
         gotoAndStop('Run'); 
         scaleX = 1; 
        } 
        else if ((LeftKeyPress)) 
        { 
         //Otherwise if on floor and left key is pressed run left 
         gotoAndStop('Run'); 
         scaleX = -1; 
        } 

        //If no key is pressed stay idle 
        if ((!RightKeyPress && !LeftKeyPress)) 
        { 
         gotoAndStop('Idle'); 
        } 
       } 


       //If on floor and can jump 
       if (CanJump) 
       { 
        //If right key is pressed run right 
        if ((RightKeyPress)) 
        { 
         x += RunSpeed; 
         gotoAndStop('Run'); 
         scaleX = 1; 
        } 
        else if ((LeftKeyPress)) 
        { 
         //otherwise if left key is pressed run left 
         x -= RunSpeed; 
         gotoAndStop('Run'); 
         scaleX = -1; 
        } 

        if ((UpKeyPress)) 
        { 
         //If up key is pressed then jump 
         JumpPower = -15; 
         CanJump = false; 
         gotoAndStop('Jump'); 
         Jumped = true; 
        } 

        //If no key is pressed stay idle 
        if ((!RightKeyPress && !LeftKeyPress && CanJump)) 
        { 
         gotoAndStop('Idle'); 
        } 
       } 
       else if (CanJump == false) 
       { 
        //Otherwise if in air and right key is pressed move right 
        if ((RightKeyPress)) 
        { 
         x += RunSpeed; 
         scaleX = 1; 
        } 
        else if ((LeftKeyPress)) 
        { 
         //Otherwise if left key is pressed then move left 
         x -= RunSpeed; 
         scaleX = -1; 
        } 
       } 


       //If Dashing is true 
       if (Dashing == true) 
       { 
        //Dash right 
        if (RightDash == true) 
        { 
         stage.addEventListener(KeyboardEvent.KEY_DOWN, SecondDash); 
         stage.removeEventListener(KeyboardEvent.KEY_DOWN, KeyPressed); 
         TweenLite.to(this,0,{blurFilter:{blurX:1000}}); 
         TweenLite.to(this,0.2,{blurFilter:{blurX:0},x:x + DashAmount,ease:Expo.easeOut}); 
         Dashing = false; 
        } 
        else if (LeftDash == true) 
        { 
         //Otherwise dash left 
         stage.addEventListener(KeyboardEvent.KEY_DOWN, SecondDash); 
         stage.removeEventListener(KeyboardEvent.KEY_DOWN, KeyPressed); 
         TweenLite.to(this,0,{blurFilter:{blurX:1000}}); 
         TweenLite.to(this,0.2,{blurFilter:{blurX:0},x:x - DashAmount,ease:Expo.easeOut}); 
         Dashing = false; 
        } 
       } 
       else if (Dashing == false) 
       { 
        stage.removeEventListener(KeyboardEvent.KEY_DOWN, SecondDash); 
       } 


      this.y += JumpPower; 
     } 


     function SecondDash(event:KeyboardEvent) 
     { 
      stage.removeEventListener(KeyboardEvent.KEY_DOWN, SecondDash); 

      if (event.keyCode == 38) 
      { 
       TweenLite.to(this,0,{blurFilter:{blurX:0}}); 
       TweenLite.to(this,0,{blurFilter:{blurY:1000}}); 
       TweenLite.to(this,0.5,{blurFilter:{blurY:0},y:y - DashAmount,ease:Expo.easeOut}); 
      } 
     } 

     function KeyUp(event:KeyboardEvent) 
     { 
      stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed); 
      RightDash = false; 
      LeftDash = false; 

      if (event.keyCode == 39) 
      { 
       RightKeyPress = false; 
      } 

      if (event.keyCode == 37) 
      { 
       LeftKeyPress = false; 
      } 

      if (event.keyCode == 38) 
      { 
       UpKeyPress = false; 
       Jumped = false; 
      } 
     } 
    } 
} 

답변

3

적어도 내가 당신의 코드에서 보는 것에서 공격 애니메이션을해라. 적어도 자신 만의 노력을하고 게시했는지 알면 도움이 될 것입니다.하지만 그 말을 듣고 몇 가지 출발점을 알려 드리겠습니다. 또한,이 게임을 만들기 위해 문서 클래스와 다른 클래스를 사용하고 있는지, 아니면 타임 라인을 사용 중인지 확실하지 않습니다. 다음은 클래스 사용에 대한 것입니다. 수업을 사용하지 않는다면 ... 지금 당장 중지하고 AS3이 실제로 무엇인지 배우십시오. 가능한 경우 AS3의 타임 라인에 코딩하지 않으려 고합니다.

"1", "2"및 "3"키로 구성된 공격이 3 건 있다고 가정 해 봅시다. var LeftDash:Boolean = False이 괜찮은 직후에이 변수를 다른 변수와 함께 사용하십시오.

private var attack1Boolean:Boolean = false; 
private var attack2Boolean:Boolean = false; 
private var attack3Boolean:Boolean = false; 

다음 당신이 함께 할 거의 같은 일을 (즉, 단지 public var을 사용하여 작동하지 않는 경우에도, 방금 완성도 .... .... private varvar의 모든 변경) keydown 및 화살표 키의 키 업. 귀하의 KeyDown 방법 안에 다음과 같은 것을 넣으십시오.

if (event.keyCode == 49) 
{ 
    attack1Boolean = true; 
} 
if (event.keyCode == 50) 
{ 
    attack2Boolean = true; 
} 
if (event.keyCode == 51) 
{ 
    attack3Boolean = true; 
} 

다음 KeyUp 방법, 추가
if (event.keyCode == 49) 
{ 
    attack1Boolean = false; 
} 
if (event.keyCode == 50) 
{ 
    attack2Boolean = false; 
} 
if (event.keyCode == 51) 
{ 
    attack3Boolean = false; 
} 

지금 당신이 공격을 실시 할 준비가 다음과 같습니다. 이미 공격을 위해 3 가지 애니메이션을 제작했다고합니다. 즉, 각 공격에는 타임 라인이 있어야합니다 (하나의 타임 라인에 3 개를 모두 가질 수 있지만 프레임별로 구분할 수도 있지만 권장하지는 않습니다). 원하는 것을하기 위해 (다음 공격이 일어나기 전에 각 애니메이션을 완료하십시오) gotoAndStop 또는 gotoAndPlay을 사용해야합니다.

각 애니메이션에 대해 .as 파일을 새로 만드는 것이 가장 유용합니다. 3 개의 애니메이션을 모두 하나의 타임 라인에 결합한 경우 ... 3 개의 새로운 .as 파일을 새로 만들면됩니다. 이제는 일반적인 방법으로 모두 연결할 수 있습니다 (이 작업을 수행하는 방법을 모르는 경우 ... 다시 한 번 ... 실제 AS3 튜토리얼을 시작하십시오 ... 앞서 나아가고 있습니다.)

당신은 넣어 당신의 바르에서 맨 위에있는, 그래서이 새로운 클래스 파일의 인스턴스를 만들어야합니다 다음 (당신은 등 새로운 클래스 Animation1, Animation2을 ... 이름을합니다.)

private var animation1:Animation1; 
private var animation2:Animation2; 
private var animation3:Animation3; 

는 그런 기능 Player 지금 당신의 애니메이션을 사용할 준비가되어 있어야합니다
animation1 = new Animation1(); 
animation2 = new Animation2(); 
animation3 = new Animation3(); 

을 넣어. 당신의 Update 방법로 이동하여 캐릭터 애니메이션을 시작하고 다른 사람이 완료되면 그렇게 우리는 단 하나의 공격을 사용할 수 있도록해야 다음

//note, the animation1.currentFrame == 1 doesn't have to be 1...it's just the initial starting frame of the animation 
if (attack1Boolean && 
    animation1.currentFrame == 1 && 
    animation2.currentFrame == 1 && 
    animation3.currentFrame == 1) 
{ 
    animation1.x = //character.x if you have a class...this.x for yours 
    animation1.y = //character.y if you have a class...this.y for yours 
    addChild(animation1); 
    attack1Boolean = false; 
    if (animation1.currentFrame = //the last frame of animation1...a number) 
    { 
     animation1.gotoAndStop(1); 
     removeChild(animation1); 
    } 
} 

if (attack2Boolean && 
    animation1.currentFrame == 1 && 
    animation2.currentFrame == 1 && 
    animation3.currentFrame == 1) 
{ 
    animation2.x = //character.x if you have a class...this.x for yours 
    animation2.y = //character.y if you have a class...this.y for yours 
    addChild(animation2); 
    attack2Boolean = false; 
    if (animation2.currentFrame = //the last frame of animation2...a number) 
    { 
     animation2.gotoAndStop(1); 
     removeChild(animation2); 
    } 
} 

if (attack3Boolean && 
    animation1.currentFrame == 1 && 
    animation2.currentFrame == 1 && 
    animation3.currentFrame == 1) 
{ 
    animation3.x = //character.x if you have a class...this.x for yours 
    animation3.y = //character.y if you have a class...this.y for yours 
    addChild(animation3); 
    attack3Boolean = false; 
    animation3.gotoAndStop(1); 
    if (animation3.currentFrame = //the last frame of animation3...a number) 
    { 
     animation3.gotoAndStop(1); 
     removeChild(animation3); 
    } 
} 

를 추가합니다. 또한 애니메이션이 있어야하는 조건은 자체 프레임 1이기 때문에 키를 누른 상태에서 반복적으로 애니메이션을 시작하는 문제가 해결되었습니다 (키를 계속 누르고 있으면 공격이 시작됩니다). 일단 애니메이션이 끝났 으면 좋겠지 만 큰 문제는 아닌 것 같아요.

이 모든 것을 시도해보십시오. 메모리에서이 작업을 수행했기 때문에 몇 개의 버그가 있는지 말해주십시오.

+0

도움을 주셔서 감사합니다하지만 난 그냥 더 튜토리얼을하거나 그냥 포기 것, 그것이 작동 할 수없는 것, 내가/프로그래밍 코딩 추측하는 것은 모든 사람 덕분위한 것이 아닙니다 어쨌든 – user2350724

+0

검색 "마이클 제임스 Avoider 게임 자습서 "구글. 나는 완벽한 게임을 만드는 방법을 가르쳐주는 가장 좋은 게임 중 하나라고 생각합니다. 그것은 아마도 당신이 그것을 다시하고 자신의 게임을 비슷하게 만들면 잘 배우는 데 일주일 정도 걸릴 것입니다. 그러나 일주일 정도 지나면 약속이 훨씬 편안해질 것입니다. – spaderdabomb

관련 문제