android – LibGDX ShapeRenderer圆绘图

前端之家收集整理的这篇文章主要介绍了android – LibGDX ShapeRenderer圆绘图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经尝试了几种解决方案来绘制圆圈以生成坐标.
它不起作用,但我不知道fillCircle方法有什么问题?我怎样才能更换它?

信息:

FilledCircle cannot be resolved or is not a field

码:

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);
     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,64,64);
      shapeRenderer.begin(ShapeType.FilledCircle);
      shapeRenderer.filledCircle(50,50,32);
      shapeRenderer.setColor(Color.BLACK);
      shapeRenderer.end();
      batch.end();  
}


}

解决方法

方法begin(ShapeRenderer.ShapeType类型)接受ShapeType.有3 Shapetypes:填充,线和点.没有像你使用的FilledCircle(这是错误消息对你说的).

所以,你应该使用shapeRenderer.begin(ShapeType.Filled);

另外,还没有fillCircle()方法.尝试shapeRenderer.circle(50,32);.

编辑:

这是你的代码没有一些错误.你需要了解它并完成一些部分,复制粘贴不会这样做.

@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,64);
}


@Override
public void render () {

     Gdx.gl.glClearColor(1,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,32);
      shapeRenderer.end();
}

猜你在找的Android相关文章