I got a working pong game in LibGDX but I'm now trying to add a tail to my ball so if it moves you can see a line behind it just like the game Snake.
I'm drawing simple circles now at the x/y coordinates I get but for some reason this gets messed up I'm not getting any errors.
This is how my game looks like right now:
Here is where I add the x/y coordinates to the tail classes wich I created it works fine but for some reason this gets messed up on my screen.
public void tail(){
i++;
if(i >= tail.length)i=1;
tail[i-1] = new Tail(ball.getX(),ball.getY());
tail[i] = new Tail(tail[i-1].x,tail[i-1].x);
}
I created the objects like this:
for(int i = 0; i < tail.length; i++){
tail[i] = new Tail(0,0);
}
And my Tail class looks like this:
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
public class Tail {
public float x;
public float y;
ShapeRenderer shapeRenderer;
SpriteBatch batch;
public boolean active = false;
public Tail(float x, float y){
shapeRenderer = new ShapeRenderer();
batch = new SpriteBatch();
this.x = x;
this.y = y;
batch.begin();
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.circle(x, y, 16);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.end();
batch.end();
Gdx.app.log("TailX"+x, "TailY"+y);
}
}
Why is this not working and is the tail class drawing the circles like the image above? And whats the best way to solve this problem so I get a following tail?!
0 comments:
Post a Comment