找不到错误符号变量ShapeType

时间:2017-11-16 13:00:01

标签: libgdx

我刚开始学习libgdx中的游戏开发 它在这一行显示错误

shapeRenderer.begin(ShapeType.Point);

显示的错误是: -

  

错误:(80,29)错误:找不到符号变量ShapeType

这是我的完整课程

   import com.badlogic.gdx.ApplicationAdapter;
   import com.badlogic.gdx.Gdx;
   import com.badlogic.gdx.graphics.GL20;
   import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
   import com.badlogic.gdx.math.*;
   import com.badlogic.gdx.utils.*;
   import java.util.*;
   public class Starfield extends ApplicationAdapter {

   private static final float STAR_DENSITY = 0.01f;
   ShapeRenderer shapeRenderer;
   Array<Vector2> stars;

   @Override
   public void create() {

   shapeRenderer=new ShapeRenderer();
   initStars(0.01f);

   }

   public void initStars(float density) {

   int a = Gdx.graphics.getWidth();
   int b=Gdx.graphics.getHeight();
   int count=Integer.parseInt(Float.toString(a*b*density));
   stars=new Array<Vector2>(count);
   Random random=new Random();
    for(int i=0;i<count;i++)
    {
        int x=random.nextInt(a);
        int y=random.nextInt(b);
        stars.add(new Vector2(a,b));
    }
   }

   @Override
   public void resize(int width, int height) {
    initStars(STAR_DENSITY);
    shapeRenderer = new ShapeRenderer();
   }

   @Override
   public void render() {

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


    shapeRenderer.begin(ShapeType.Point);

   for(Vector2 star : stars)
   {
   shapeRenderer.point(star.x,star.y,0);
   }

   shapeRenderer.end();
   }

   @Override
   public void dispose() {

   shapeRenderer.dispose();
    super.dispose();
 }
 }

1 个答案:

答案 0 :(得分:1)

ShapeTypeShapeRenderer类中的枚举。

以这种方式使用:

shapeRenderer.begin(ShapeRenderer.ShapeType.Point);