I want to create a line that is created by the movement of an Actor, like, a "pen down" tool, That draws a line in the path of the moving actor. How can I do this‽
public void act()
{
//after your normal code....
//add this call to addInk()
addInk();
}
//then you define addInk()
public void addInk()
{
if(hasMoved()) //check if has moved to not add Ink twice in same place.
getWorld().addObject(new Ink(), getX(), getY());
}
//hasMoved you'd define here...
public void hasMoved()
{
boolean moved = (lastX != getX() && lastY != getY());
//you'd have to define lastX and lastY as "int"s at the top of your class
lastX = getX();
lastY = getY();
return moved;
}
public class Ink extends Actor
{
private int frame; //to add in animation.
public Ink()
{
setImage(whateverImageYouWant);
frame = 0;
}
public void act()
{
//if you don't care for the animation, just don't have anything in the act method.
blot();
}
public void blot()
{
//this will just make the image fill out over time, as opposed to staying constant.
if(frame < 5) {
getImage().scale(frame*4 + 1, frame*4 + 1);
frame++;
}
}
}