Hi, I have a question about Images. Is there a way to make an image trace/follow a line? If so, can you please explain on how to do it? I want know how to make the image trace a line from point A to point B.
Reading parts of this might help you http://www.java-gaming.org/index.php?topic=25402.0. I have yet to add this feature myself so that is all I can provide, good luck!
Or you meant follow complex line like tower defense, with all of that curves?
direction of line: D=|B-A|
parameterize: F(t) =Dt+A
where ‘t’ is on [0,1]
brain-dump untested pseudocode:
public void setup(Vect2f a, Vect2f b)
{
// store initial point
x0 = a.x;
y1 = a.y;
// compute and store direction of line
dx = b.x-x0;
dy = b.y-y0;
// compute and store length of the line segment
len = (float)(Math.sqrt(dx*dx+dy*dy));
// normalize direction
float t = 1.f/len;
dx *= t;
dy *= t;
}
/** Set 'r' to the blah, blah and returns 'r'. */
public Vect2f position(Vect2f r, float t)
{
r.x = x0 + t*dx;
r.y = y0 + t*dy;
return r;
}
I meant more of, just following a straight line.
Just set the y to a number and never change the y, but every update add to the x of the image.
If you want it to go up add to the y instead of the x.
Sorry if any spelling mistakes I’m on my phone
Never change X -> vertical move.
Never change Y -> horizontal move.
All lines are straight.
Yeah I think he means any line not just vertical/horiz lines.
Yea, that’s what I was asking for. I understand how to make Vert and Horiz lines, just wondering how to make an image follow a line that has a certain amount of degrees to it.