[英]How to drawing circles libgdx
Ok you can do this make custom arc and assign colors to them 好的,您可以执行此操作以创建自定义圆弧并为其分配颜色
how to make a custom arc without and joint from center is: 如何在没有中心接合的情况下创建自定义弧:
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);
}
}
make sweeps in segment of 90 to get your arc and now how to make these arcs in game screen do this to make a arc in your code 在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
this will give you an arc and it comes to rotate change your startangle Without changing your sweep like startangle++ instead of startangle in above code where startangle is defined as float startangle = 0; 这将为您提供一个弧线,并且可以旋转来更改起始角度,而无需像startangle ++那样更改扫描范围,而不是在上面的代码中将起始角度定义为float startangle = 0的起始角度
hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.