Reputation: 3
I have just started to learn game develpoment in libgdx It is showing error in this line
shapeRenderer.begin(ShapeType.Point);
error displayed is:-
Error:(80, 29) error: cannot find symbol variable ShapeType
this is my complete class
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();
}
}
Upvotes: 0
Views: 136
Reputation: 20140
ShapeType
is an enum inside ShapeRenderer
class.
Use in this way :
shapeRenderer.begin(ShapeRenderer.ShapeType.Point);
Upvotes: 1