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()
類對象。