How do I loop multiple tween animations?

0 favourites
  • 6 posts
From the Asset Store
Calculate parabolic trajectories and tween objects over them.
  • Hi guys,

    I need to loop the enemy's movement to the pattern.

    When I use loops (for, while, repeat), the tween's animations are only played once anyway.

    What am I doing wrong? :)

  • It will be much easier to use MoveTo behavior here - you can give it waypoints for the entire path.

    If you need to use Tween, I would suggest giving tags to tweens. Move them all into a function. Instead of using "Repeat 10 times" loop, run the function once. When the last tween ends (use "On Tween Finished" trigger), run the function again.

  • It will be much easier to use MoveTo behavior here - you can give it waypoints for the entire path.

    Do you mean adding waypoints coordinates to the Array and loading them in the loop? Because Move To behaviors doesn't work in a loop for me either.

    If you need to use Tween, I would suggest giving tags to tweens. Move them all into a function. Instead of using "Repeat 10 times" loop, run the function once. When the last tween ends (use "On Tween Finished" trigger), run the function again.

    I tried it, but the object behaves strangely, moving randomly :(

    Maybe you know of some tutors or manual on topic of waypoints and tween tags?

    I would appreciate it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • With MoveTo you can do something like this:

    Repeat 10 times
     Sprite MoveTo position (startX, startY+loopindex*100) (add waypoint)
     Sprite MoveTo position (startX+50, startY+loopindex*100+50) (add waypoint)
    

    In your screenshot you left tween tags empty "". Just give them descriptive tags like "move_left", "new_cycle" etc. Then you will be able to track the progress of every tween using events like "Tween is playing", "Tween finished".

  • That's great! Thanks a lot! Using MoveTo works fine. Only I gave up the loop and use the function in time slots by Every X seconds. Because Repeat calls the function every tick, if I understand correctly, and the loops overlap each other. I tried using On Arrived, but it doesn't work. The sprites move strangely. I think it's because I have Wait X seconds timers in the body of the function.

  • Because Repeat calls the function every tick, if I understand correctly, and the loops overlap each other.

    Yes, any condition runs on every tick, unless you put it inside some triggered event or a function.

    I assumed you would use my code inside "Enemy on created" event or something like that.

    The code in your last screenshot is too complicated and possibly buggy, especially with multiple enemies.. You should either create all waypoints for the full path in one go, or use "On arrived" trigger to move to the next point. I also suggest using Timer behavior instead of "Every x seconds" and "Waits" - it gives you much more control and you can run different timers for each enemy instance.

    For example, if you you need an enemy to move to point A, wait 1 second, move to point B, wait 3 seconds, then you should use this sequence of events (in pseudocode):

    On created: Move to A
    On arrived to A: Start timer "moveToB" for 1 second
    On Timer "moveToB": Move to B
    On arrived to B: Start timer "patrol" for 3 second
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)