Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中很难沿着路径旋转精灵。_Java_Animation_Game Physics_Slick2d - Fatal编程技术网

在Java中很难沿着路径旋转精灵。

在Java中很难沿着路径旋转精灵。,java,animation,game-physics,slick2d,Java,Animation,Game Physics,Slick2d,我目前正在用Slick2D创建一个简单的游戏,它需要一个沿着用户确定的设定路径飞行的计划。目前,我有一个平面(它是一个精灵),可以沿着坐标路径。但是,我很难旋转平面精灵,使飞机的机头跟随路径 我编写了以下方法来帮助计算平面所需的旋转角度,但它似乎无法正常工作。感谢您的帮助 /** * Calculate the rotation for the plane * @return The rotation in degrees that the plane must do */ publi

我目前正在用Slick2D创建一个简单的游戏,它需要一个沿着用户确定的设定路径飞行的计划。目前,我有一个平面(它是一个精灵),可以沿着坐标路径。但是,我很难旋转平面精灵,使飞机的机头跟随路径

我编写了以下方法来帮助计算平面所需的旋转角度,但它似乎无法正常工作。感谢您的帮助

/**
 * Calculate the rotation for the plane 
 * @return The rotation in degrees that the plane must do 
 */
public int calculateRotation()
{
    int[] spriteCenter = {locationX + width/2, locationY + height/2};   
    double deltaX = spriteCenter[0] - target[0];
    double deltaY = spriteCenter[1] - target[1];

    double theta = Math.atan2(deltaY,deltaX);

    return (int) Math.toDegrees(theta);
}

你结帐了吗:?是的,我结帐了,但是我在理解它时遇到了一些困难,因为它看起来相当高级(我的三角架已经生锈了)。我的理解是,这应该不难实现。