![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | YorkshireKev |
I have an animated sprite that follows a pattern defined by a Path2D, using PathFollow2D. The path is not closed and ends in a different place to where is starts. What I am trying to do is get the PathFollow2D to loop, but have each iteration start where the sprite finished.
Currently the loop just makes the sprite jump back to it’s original starting position.
Is there an easy way to achieve this behaviour?
Things i’ve tried, without success:
I have tried setting the parent position.x and position.y when the unit_offset get to > 1. I thought this almost worked, but I don’t seem to be able to get a compatible current position of the sprite. So while I can us this technique as a point to change the starting position on each loop, I can’t get figure out how to get the current position of the sprite in a format I can use.
I also thought I could keep the path separate from the sprite (by not having it as a child node) and then just use the PathFollow2D coordinates to manually update the sprite position. I’ve not had much luck here either as the coordinates don’t seem to be the same as the viewports.
I think what happens with a Path2D
(and to a lesser extent PathFollow2D
) is that the values for a path are first computed, and put into a special array. So what you may have to do is update this special array (I think it’s a PoolVector2Array
).
Ertain | 2019-03-24 23:06
Thanks Ertain. In the end I managed to change the origin of the path using the global viewport coordinates. So thankfully in the end I didn’t have to manipulate the Path2D array.
YorkshireKev | 2019-03-25 19:20
Glad to hear that.
Ertain | 2019-03-25 21:34