【发布时间】:2017-05-27 16:10:08
【问题描述】:
我正在尝试使用 libgdx 来制作我的第一个简单游戏。我设法让一条线旋转。
我没有完成的是添加一条垂直线,使其成为十字形,然后旋转这个形状。
public void render(ShapeRenderer renderer) {
renderer.set(ShapeType.Line);
renderer.setColor(COLOR);
/**
* finding the angle
*/
float elapsedNanoseconds = TimeUtils.nanoTime() - initialTime;
float elapsedSeconds = MathUtils.nanoToSec * elapsedNanoseconds;
float elapsedPeriods = elapsedSeconds / 2.0f;
float cyclePosition = elapsedPeriods % 1;
float x = WORLD_SIZE / 2 + radius * MathUtils.cos(MathUtils.PI2 * cyclePosition);
float y = WORLD_SIZE / 2 + radius * MathUtils.sin(MathUtils.PI2 * cyclePosition);
//line rotates and moves at the same time.
renderer.line(position.x - x, position.y + y, position.x + x, position.y - y);
}
position 是一个Vector2() 类对象,每delta 秒更新一次,并保存当前行的中心。
【问题讨论】: