我正在创建棋盘游戏,我需要为玩家画圆圈(2-5人)。我可以用ShapeRenderer绘制它们,但是我不能控制圆圈(改变位置、半径等)。所以我需要使用for循环创建2-5循环类对象(我想用for循环来实现)。我该怎么做呢?
谢谢!
发布于 2017-03-14 11:47:05
您的圆圈是只需要在视图或它需要在模型(例如。圆圈之间的碰撞检测)。
如果只查看,则取一个圆形的.png图像。创建Sprite或Image对象并使用该对象,否则您可以使用ShapeRenderer绘制圆圈。
可以使用ShapeRender对象更改位置,将此Actor与scene2d一起使用
编辑
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);发布于 2017-03-14 11:43:58
您可以创建一个循环类,并使用for-循环遍历它们。例如:
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);
}
}这将允许您动态地更改命名圆的位置和大小。另外,如果您不介意使用内置的东西,您可以转到他们的wiki中,看到他们有一个类似于此的圆对象,并有一个额外的功能,比如一个“重叠”方法。
发布于 2017-03-14 11:10:20
你可以用ShapeRenderer画圆圈白化,你可以画另一个物体,而不是移动它们,例如,我做了一条蛇,它比你能移动它们
https://stackoverflow.com/questions/42783854
复制相似问题