0
我正在尝试使用libgdx尝试制作我的第一个简单游戏。我设法旋转了一条线。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()
类对象。