Вопрос

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