0

화면에 동전을 던질 수있는 작은 게임을 만들려고합니다. 내가 애니메이션의 종류를 검색하는 동안 나는 내 목표에 따라 이벤트를 사용자 정의 관리 페이지가장자리가 튀어 오름

http://mobile.tutsplus.com/tutorials/android/android-gesture/

을 발견,하지만 난 화면에 경계를 설정 관리 할 수 ​​있도록 동전 (비트 맵)가 가장자리로 올 때 다시 튀어 오를 것입니다.

몇 가지 계산을 시도했지만 결국 엔 가장자리의 접촉점을 기준으로 동전이 이상하게 움직입니다.

누군가가 웹 사이트 아래

답변

0

에 작업 코드에 따라, 그것에 대해 좀 도와 줄래 나의 탁구 게임에서 샘플 코드입니다. 각 객체는 위치 (x, y)와 속도를가집니다. 움직임은 위치에 속도가 적용됩니다. 한 가지 추가 정보는 화면 좌표계가 왼쪽 상단 구석에서 시작한다는 것입니다. Y 축은 아래로 내려가지만 증가합니다. 화면 좌표는 0부터 시작하기 때문에, 경계는 screen.width 될 -1 screen.height -1

@Override 
public void onDraw(Canvas c){ 

    p.setStyle(Style.FILL_AND_STROKE); 
    p.setColor(0xff00ff00); 




      // If ball's current x location plus the ball diameter is greater than screen width - 1, then make speed on x axis negative. Because you hit the right side and will bounce back to left. 
     if((Px+ballDiameter) > width - 1){ 

      Vx = -Vx; 
     } 
      // If ball's current y location plus the ball diameter is greater than screen height -1, then make speed on y axis negative. Because you hit the bottom and you will go back up. 
     if((Py + ballDiameter) > height - 1){ 

      Vy = -Vy; 
     } 
      // If current x location of the ball minus ball diameter is less than 1, then make the speed on x axis nagative. Because you hit to the left side of the screen and the ball would bounce back to the right side 
     if((Px - ballDiameter) < 1){ 

      Vx = -Vx; 
     } 
      // If current y location of the ball minus ball diameter is less than 1, then make the speed on y axis negative. Because the ball hit the top of the screen and it should go down. 
     if((Py - ballDiameter) <1){ 
      Dy = 1; 
      Vy = -Vy; 
     } 




      Px += Vx; // increase x position by speed 
      Py += Vy; // increase y position by speed 

     c.drawCircle(Px, Py, ballDiameter, p); 



     invalidate(); 

} 
+0

감사 그것이 정말 나에게 – koraxis

+0

도움을 내가 듣고 기뻐요. – neo

관련 문제