Reputation: 759
I'm creating board game and I need to draw circles for players (2-5 players). I can draw them using ShapeRenderer but then I don't have control over circles (change position, radius, etc.). So I need to create 2-5 Circle class object using for loop (I want to do it with for loop). How can I do it?
Thanks!
Upvotes: 0
Views: 778
Reputation: 20140
Is your Circle is required in view only or it required in model (eg. Collision detection between circles) too.
If view only then take a circular .png image. Create Sprite
or Image
object and use that otherwise you can draw Circle using ShapeRenderer.
you can change position using ShapeRender object Use this Actor with scene2d
EDIT
public static Pixmap getPixmapCircle(int radius, Color color, boolean isFilled) {
Pixmap pixmap=new Pixmap(2*radius+1, 2*radius+1, Pixmap.Format.RGBA8888);
pixmap.setColor(color);
if(isFilled)
pixmap.fillCircle(radius, radius, radius);
else
pixmap.drawCircle(radius, radius, radius);
pixmap.drawLine(radius, radius, 2*radius, radius);
Pixmap.setFilter(Pixmap.Filter.NearestNeighbour);
return pixmap;
}
Texture texture=new Texture(getPixmapCircle(10, Color.RED, true));
Image image=new Image(texture);
or
Sprite sprite=new Sprite(texture);
Upvotes: 0
Reputation: 1279
You can create a circle class and iterate through them with a for-loop. For example:
public class MyCirlce{
private float radius;
private Vector2 position;
public MyCircle(float xPos, float yPos, float radius){
position = new Vector2(xPos, yPos);
this.radius = radius;
}
public void translate(float xAmount, float yAmount){
position.x += xAmount;
position.y += yAmount;
}
public void changeSizeBy(float changeAmount){
radius += changeAmount;
}
public void render(ShapeRenderer render){
render.circle(position.x, position.y, radius);
}
}
This will allow you to dynamically change the position of named circles and the size. Also, if you didn't mind using built in things, you can go to their wiki and see that they have a Circle object similar to this with extra functionality like a 'Overlaps' method.
Upvotes: 1
Reputation: 59
you can draw circle whitout using ShapeRenderer you can draw another object than move them for example I make a snake whit lable than you can move them
Upvotes: 0