문제

I am porting a game I have made, from Windows (Visual Studio c# XNA4) to Android.

In the game, I need to find the location of the users "touch" (Which I have done), and then "point" the player to this touch location (draw the player bitmap at this angle).

In c# and XNA4, I used the following:

Matrix rotationMatrix = Matrix.CreateRotationZ(playerAngle);
PlayerDirection = Vector2.Transform(up, rotationMatrix); 

If the players position was

x = 200;
y = 200; 

And the touch co-ordinates were

x = 300;
y = 300;

How would I make the player "point" at where the user touched?

도움이 되었습니까?

해결책

In Java (I assume you are using Java for Android) you would do the following to find the angle:

private double getAngle(double x1, double y1, double x2, double y2)
{
    return Math.atan2(y2-y1, x2-x1);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top