Java – try to draw a circle in libgdx

It's very basic, but I can't figure out what's wrong Basically, I want to draw a circle around an area of one of my objects I initialized a shaperender (named srdebugcircle) in the constructor and used a for loop in the render () method to draw each object

for (GameObject object : levels.get(LEVEL_INDEX)) {
        if (object.getType() == ObjectType.SWINGING_SPIKES) {
            object.draw(batch);
            srDebugCircle.begin(ShapeType.Filled);
            srDebugCircle.circle(object.getxPos() + object.getWidth()/2,object.getyPos(),object.getWidth()/2);
            srDebugCircle.setColor(Color.BLACK);
            srDebugCircle.end();
        }

        if (object.getType() == ObjectType.COIN && (Coin) object).isVisible()) {
            object.draw();
        }
        ...
}

The problem is that when I add circle code, I only see 4 of the 15 objects When I delete / comment on it, it works as usual – but in both cases, I will never see a black circle

I particularly talked about this part:

srDebugCircle.begin(ShapeType.Filled);
            srDebugCircle.circle(object.getxPos() + object.getWidth()/2,object.getWidth()/2);
            srDebugCircle.setColor(Color.BLACK);
            srDebugCircle.end();

Who can understand why I have this problem?

Solution

Another option for springrbua's answer is to use pixmaps instead of shaperer Switching between sprite batch and shaperrender is an expensive operation, and pixmaps does not need to end sprite batch Pixmap provides fewer drawing methods than shaperer, but it does include drawing a solid circle

Pixmap pixmap = new Pixmap(width,height,Pixmap.Format.RGBA8888);
pixmap.setColor(Color.BLACK);
pixmap.fillCircle(x,y,r);
Texture texture = new Texture(pixmap);

// render
batch.begin();
batch.draw(texture,x,y);
batch.end();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>