[英]How to drawing circles libgdx
好的,您可以執行此操作以創建自定義圓弧並為其分配顏色
如何在沒有中心接合的情況下創建自定義弧:
public Arc(Color color){
this.color = new Color(color);
renderer = super.getRenderer();
}
public Color getArcColor(){
return color;
}
/** Draws an arc using {@link ShapeType#Line} or {@link ShapeType#Filled}. */
public void arc (float x, float y, float radius, float start, float degrees,int segments) {
// int segments = (int)(6 * (float)Math.cbrt(radius) * (degrees / 360.0f));
if (segments <= 0) throw new IllegalArgumentException("segments must be > 0.");
float colorBits = color.toFloatBits();
float theta = (2 * MathUtils.PI * (degrees / 360.0f)) / segments;
float cos = MathUtils.cos(theta);
float sin = MathUtils.sin(theta);
float cx = radius * MathUtils.cos(start * MathUtils.degreesToRadians);
float cy = radius * MathUtils.sin(start * MathUtils.degreesToRadians);
for (int i = 0; i < segments; i++) {
renderer.color(colorBits);
Gdx.gl.glLineWidth(width_of_line);
Gdx.gl.glEnable(GL20.GL_BLEND);
renderer.vertex(x + cx, y + cy, 0);
float temp = cx;
cx = cos * cx - sin * cy;
cy = sin * temp + cos * cy;
renderer.color(colorBits);
renderer.vertex(x + cx, y + cy, 0);
}
}
在90的范圍內進行掃掠以獲取弧線,現在如何在游戲屏幕中進行這些弧線轉換以在代碼中生成弧線
Arc a;
...
...
in create:
a= new Arc(Color.RED);
...
in render:
a.begin(ShapeRenderer.ShapeType.Line);
a.arc(x,y, (float) radius, startangle, sweep, 100);
a.end
這將為您提供一個弧線,並且可以旋轉來更改起始角度,而無需像startangle ++那樣更改掃描范圍,而不是在上面的代碼中將起始角度定義為float startangle = 0的起始角度
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.