Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX ShapeRenderer circle drawing

I have tried several solutions for drawing circles to generated coordinates. It is not working, but I do not know what is the problem with filledCircle method? How can I 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();  
}


}
like image 988
plaidshirt Avatar asked Nov 03 '14 14:11

plaidshirt


2 Answers

The method begin(ShapeRenderer.ShapeType type) accepts a ShapeType. There are 3 Shapetypes: Filled, Line and Point. There is no FilledCircle like you are using (that's what the error message says to you).

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

Also, there is not filledCircle() method. Try shapeRenderer.circle(50, 50, 32);.

EDIT:

This is your code without some of the mistakes. You'll need to understand it and complete some parts, copy-paste won't do it.

@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();
}
like image 167
MadEqua Avatar answered Nov 18 '22 14:11

MadEqua


You cannot initialize a shaperenderer inside of a batch, you will stop batch (batch end) and start the shaperenderer, when you stopped the shaperenderer you can start the batch again. Sorry for the fails, my english are no very good

like image 40
Rafale encina Avatar answered Nov 18 '22 12:11

Rafale encina