I want to make a Snake game, but I don't know how to make the tail move together with the head. I want to use an array but I don't know how to program it to move together with the head.
private Actor behind;
public void move(Actor ahead, boolean addBehind)
{
if (behind != null) behind.move(this, addBehind);
else if (addBehind) getWorld().addObject(behind = new Body(), getX(), getY());
setLocation(ahead.getX(), ahead.getY());
}behind.move(this, false); // moves body without adding length (false), in this case setLocation(<<newX>>, <<newY>>); // moving the head to its next location