Libgdx:围绕z轴变换vector2

本文关键字:变换 vector2 围绕 Libgdx | 更新日期: 2023-09-27 18:18:28

我正在尝试将一款塔防游戏从xna (c#)移植到libgdx (java)。

但现在我有一个问题,有一个功能,旋转子弹从塔绕z轴方向的敌人。

public void SetRotation(float value){
    rotation = value;
    velocity = Vector2.Transform(new Vector2(0, -speed), Matrix.CreateRotationZ(rotation));
}

这是c#中使用xna的代码。有人知道在libgdx中怎么做吗?

这里列出了教程的链接:http://xnatd.blogspot.de/2010/10/tutorial-7-firepower.html.

我希望有人能帮助我。

Libgdx:围绕z轴变换vector2

Vector2#rotate绕Z轴旋转矢量。注意它需要角度。如果角度是以弧度为单位,则使用rotateRad方法。

velocity.set(0, -speed).rotate(value);
//or
velocity.set(0, -speed).rotateRad(value);