Order of Events

I am working on a TCG based game and I am having a hard time getting events to go in a specific order. Everything kinda happens at once virtually simultaneously.

It should go:

1. Play "Start Duel" animation and finish 2. Draw 5 cards for each player pausing slightly after each card is drawn 3. Actually begin the duel 4. Play "Draw Phase" animation and draw starting player's first card etc.

The problem is even though everything looks in order in my code , stuff happens out of sequence like the “Start Duel” animation is still going after both player’s initial hands are drawn. That animation should finish before any cards are drawn.

How do I have the code wait for the animation to finish before executing the next event?

I’m a little confused on where to place everything to have it do what I want when it should happen.

The “Start Duel” animation is done in a Timer.

App.Open happens before most every other one (although there are some cool things you can do to make this NOT true)
Control Open events happen before the Window Open event

After that there is no “defined” event ordering and you should not write code that relies on ordering of events
Especially because they will be different between OS X, Windows & Linux

While what Norman says is obviously correct… I’m not sure it applies to what you are doing… as the “events” you describe in your bullet list are not the “system type” events that Norman is describing.

Do you listed events happen OUT OF ORDER?
or is it they are happening IN ORDER, but each event in the sequence is starting before the previous event has “completed”

One possible solution is to have the completion of each event trigger the start of the next one.
This way your “Start Duel” animation upon completion will tell the “Draw Cards” event to begin, etc.

[quote=285950:@Dave S]While what Norman says is obviously correct… I’m not sure it applies to what you are doing… as the “events” you describe in your bullet list are not the “system type” events that Norman is describing.

Do you listed events happen OUT OF ORDER?
or is it they are happening IN ORDER, but each event in the sequence is starting before the previous event has “completed”

One possible solution is to have the completion of each event trigger the start of the next one.
This way your “Start Duel” animation upon completion will tell the “Draw Cards” event to begin, etc.[/quote]
The events happen in order based on my code but the next event happens before the previous one finishes.

[quote=285948:@Norman Palardy]App.Open happens before most every other one (although there are some cool things you can do to make this NOT true)
Control Open events happen before the Window Open event[/quote]

Actually, I noticed that usually, the default window opens BEFORE App.Open. I had assumed as you say, and only after a bug before of that, I realized it by placing debuglogs in each open.

In which event is your code placed ?

Why do you use a timer here? The timers need to signal back to the main routine that they have finished their job and the next task can be started. But I don’t see a benefit of a timer here.

So how to fix this? Concentrate first on getting the first 2 items on your list behaving. Make a simple example out of your code until you understand what happens.

Animation is a tricky subject. It sounds like you’re on the right track, but you probably need to also use a timer to do the next thing once the animation stops.

For example, if step 1 should take 1 second to complete, have a timer wait 1 second and start step 2. Xojo.Core.Timer.CallLater could help with this.

[quote=285947:@Charles Fasano]I’m a little confused on where to place everything to have it do what I want when it should happen.

The “Start Duel” animation is done in a Timer.[/quote]

Charles, you may want to stop the timer when you start the duel, and restart it when it is complete.

Something like this in the Action event :

Me.Mode = Timer.ModeOff //Do the duel

And at the end of the duel :

Timer1.Mode = Timer.ModeMultiple

Or, start a single timer action at the end of each duel. The timer is set to Off in the Inspector. Then when you want to start a duel do :

Timer1.Mode = Timer.ModeSingle

That way only one duel takes place. But at the end of the duel code, do that again so another duel starts.

I’ve changed some of the code. I moved some of the code from the Window.Open Event to methods. I moved the code that is supposed to deal the initial hand to a method that is triggered in the timer when the animation is finished.

I can’t wait to see what happens when I run this code in Windows as I’m working on this using a Mac and Windows seems to behave quite differently especially graphics wise than Mac OS X.

Quick question about timers. Are they best when it comes to simple animation? For now the only animation I need is, in essence, a flipbook type animation where I have several still images with transparency that need to be displayed in sequence at a specified framerate.

For example when someone’s deck is being shuffled, a coin flip, a dice roll, etc. Nothing where an object moves from across the window yet.

Yes, absolutely use timers. For that kind of animation, you might also check out my Animation Kit, specifically the AnimationKit.FrameTask class.

I don’t see a download button.

Sorry, that’s just the docs. Site here: https://thezaz.com/code/animationkit/

Yes, timers are the way to animations, especially as you describe.

You may want to create specialized container controls with multiple timers in their open event that animate a canvas, or even simply the backdrop of the CC, so when you want, say, a flipping coin, all you need to do is to http://documentation.xojo.com/index.php/Containercontrol a new instance, and it animates automatically.

[quote=286131:@Michel Bujardet]Yes, timers are the way to animations, especially as you describe.

You may want to create specialized container controls with multiple timers in their open event that animate a canvas, or even simply the backdrop of the CC, so when you want, say, a flipping coin, all you need to do is to http://documentation.xojo.com/index.php/Containercontrol a new instance, and it animates automatically.[/quote]
Will I be able to have the background of the container control transparent?

Basically my animations for now just need to play in the middle of the playing area to stress certain actions such as the beginning of a new phase of a player’s turn or the beginning of the next player’s turn. But the game sort of needs to pause while the animation takes place and then resumes once the animation is finished.

Yes, as default a ContainerControl is transparent, like a Canvas.

If the timer is inside each ContainerControl, you will have simultaneous animations.