Line Drawing LibGDX ShapeRenderer

I tried several solutions for drawing circles with generated coordinates. It does not work, but I do not know what is the problem with the fillCircle method? How to replace it?

Message:

FilledCircle cannot be resolved or is not a field

code:

package com.example.game; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; public class MainClass extends ApplicationAdapter { SpriteBatch batch; OrthographicCamera camera; ShapeRenderer shapeRenderer; private Sprite sprite; @Override public void create () { shapeRenderer = new ShapeRenderer(); batch = new SpriteBatch(); } @Override public void render () { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glDisable(GL20.GL_BLEND); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw(sprite, 200, 200, 64, 64); shapeRenderer.begin(ShapeType.FilledCircle); shapeRenderer.filledCircle(50, 50, 32); shapeRenderer.setColor(Color.BLACK); shapeRenderer.end(); batch.end(); } } 
+6
source share
1 answer

The begin(ShapeRenderer.ShapeType type) ShapeType takes a ShapeType . There are 3 Shapetypes : Filled, Line and Point. There is no FilledCircle how you use (what the error message tells you).

So you should use shapeRenderer.begin(ShapeType.Filled);

In addition, there is no filledCircle() method. Try shapeRenderer.circle(50, 50, 32); .

EDIT

This is your code without some errors. You will need to understand this and fill in some parts, copy-paste will not do this.

 @Override public void create () { shapeRenderer = new ShapeRenderer(); batch = new SpriteBatch(); camera = new OrthographicCamera(300, 480); //FILL THE VALUES HERE sprite = new Sprite(new Texture(Gdx.files.internal("badlogic.jpg"))); //FILL THE VALUES HERE sprite.setBounds(200, 200, 64, 64); } @Override public void render () { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glDisable(GL20.GL_BLEND); batch.setProjectionMatrix(camera.combined); batch.begin(); sprite.draw(batch); batch.end(); shapeRenderer.setColor(Color.BLACK); shapeRenderer.begin(ShapeType.Filled); shapeRenderer.circle(50, 50, 32); shapeRenderer.end(); } 
+17
source

Source: https://habr.com/ru/post/977652/


All Articles