简体   繁体   中英

How to drawing circles libgdx

there are 3 circles, each circle is divided into 3 parts in which color is specified, each circle should rotate in opposite directions. 在此处输入图片说明

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

 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;

hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM