How do I sequence tweens with timing?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • I'm working on a card game and the logic is getting messy. What is the best practice for tween sequencing?

    1. I use tweens to deal cards, one at a time, to the tableau

    2. When the tween is finished I enable a Group to do the next tween.

    Unfortunately, the event in #2 fires as soon as the first tween finished. (The rest of the cards are still being dealt onto the screen.)

    I tried to add a "Wait 2 seconds" to the start of the next group, but this messed up my instance picking. (It took FOREVER to figure *that* out.)

    My other group is called "Draw Next Card" and I have to use a global variable called "UI_var". I set it to 1 and then, after the first set of tweens, I set it to 0. This way it doesn't call the tweens over and over again while waiting for one of them to finish.

    It's working, but is there a better way to manage all of this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Regarding the timing, you need a way to keep track of each tween and determine which one is the last one, before changing the state of your game (by global variable, or group enabling as you're doing).

    Personally, I'd probably use (and recommend) a queue array. I would push all my tweens to a single array. As each one finishes, delete the 0th index (the one that just played), and start the next tween based on whatever is newly at the front of the line, until there are no more. All the information needed for each tween should be contained in whatever information you decide to push to the back of that array, and you wouldn't need to differentiate between types of array. They would all just go one after another until there are none left.

    Example relevant data might include what to push (UID), duration of the tween, and the target. For a pause, perhaps you could add a tween of anything for the duration you want, that doesn't actually move anything, just to keep the flow of the same system.

  • Another option is to use Timer behavior on some other object (say, the table sprite). For example, you start tweens for ten different cards, with 0.2s intervals, and each tween takes 0.5s to finish. Start a timer for 0.6s with every tween. The timer will be restarted for every card until the last one. "On timer" event will be triggered once 0.1s after the last tween has finished.

Jump to:
Active Users
There are 2 visitors browsing this topic (1 users and 1 guests)