2017-10-10 7 views
0

미니 게임을 만들고 있습니다. 나는 좌회전 할 때이 코드 내 플레이어를 회전하려면 오른쪽 picPlayer.Image.RotateFlip(RotateFlipType.RotateNoneFlipX) 내 이동 코드는 다음과 같습니다C#에서 한 번만 그림 상자를 회전하려면?

private void Form1_KeyDown(object sender, KeyEventArgs e) 
{ 
    //when one of the movement keys are pressed, 
    //makes it's variable true. 

    if (e.KeyCode == Keys.Right || e.KeyCode == Keys.D) 
    { 
     moveRight = true; 
    } 
} 

또한, 내 타이머의 프로그램입니다 :

private void tmrMovementPlayer_Tick(object sender, EventArgs e) 
{ 
    //whenever right arrow is pressed, 
    if (moveRight == true) 
    { 
     //decrease the x variable by 5 (moves right) 
     x = x + PLAYER_SPEED; 
     //check for boundaries (if the player is out of the screen) 
     if (x >= this.ClientSize.Width - picPlayer.Width) 
     { 
      //if yes, set it back to the boundary. 
      x = this.ClientSize.Width - picPlayer.Width; 
     } 
     //check the subprogram for info 
     MovePlayer(); 
    } 
} 

나는이 시점에서 무엇을해야합니까? 감사.

답변

1

그래서 덕분에, 나는 해결책을 찾아 냈다. 그것은 조금 달랐습니다. 회전을 위해서 "goingRight"라는 또 다른 부울을 만들었습니다.

if (e.KeyCode == Keys.Right || e.KeyCode == Keys.D) 
{ 
    //make move right true 
    moveRight = true; 
    //if i was going left, 
    if (goingRight == false) 
    { 
     //say it im going right 
     goingRight = true; 
     //and flip it (only if i was going left before) 
     picPlayer.Image.RotateFlip(RotateFlipType.RotateNoneFlipX); 
    } 
} 

다시 한 번 도움을 주셔서 감사합니다.

0

시도 뭔가 같은 ... 다른 대답

private void Form1_KeyDown(object sender, KeyEventArgs e) 
{ 
    //when one of the movement keys are pressed, 
    //makes it's variable true. 

    if (e.KeyCode == Keys.Right || e.KeyCode == Keys.D) 
    { 
     if (!moveRight) 
     { 
      picPlayer.Image.RotateFlip(RotateFlipType.RotateNoneFlipX) 
      moveRight = true; 
     }  
    } 
} 
+0

안녕하세요, 저는 두 가지 방법 모두에 사용했습니다. 멈추고 다시 오른쪽을 클릭하면 다시 회전하기 때문에 작동하지 않습니다. 말하자면 나는 오른쪽으로 가고있다. 멈 추면 여전히 올바른 방향을보고 있지만 다시 오른쪽을 누르면 다시 회전하고 왼쪽을 봅니다. – Qedized

+0

그리고 ... (! moveRight) 의미는 무엇입니까? 내 말은, 무슨 뜻이야! 그 코드에서 의미가 있습니까? – Qedized

+0

! 부울 반대를 의미합니다. 따라서 moveRight가 현재 false이면! moveRight는 true로 평가됩니다. –