[SOLVED] Time block and animation not synched precisely

KramerGames

  • Posts: 405
The animation "spit" consists of 15 frames, each is played for 100ms. The actor "slime" is created after 1.2 seconds because that's where the mouth is open. It all works fine the first few times, but there is a delay sneaking in and it gets worse, so after about 20 times it is off several frames.

I have asked in another thread where the timing seemed to be off: Is the time I enter in the block just something rounded/estimated?



« Last Edit: August 07, 2016, 07:30:23 am by KramerGames »
Parasites United  (Idle Parasite Game)

BMJ

  • Posts: 278
Is your spit animation set to loop? If so, the delay is likely caused by the fact that there is actually a very small amount of time in between the end of this event and the beginning of the next spit event, while your spit animation continues to loop seamlessly. If you switch to a looping animation that is already playing, it doesn't start the animation over, it just keeps it playing. So, in other words:

0ms - first spit event, starts the spit animation
1500ms - second spit event is called (but really, a tiny amount of time passes before second spit event happens because while computers are very fast, they're not "instant".), so the second spit event actually happens at about 1510ms. Doing this, after about 20 spit events, your spit animation, which has been looping continuously the whole time, is maybe about .2 secs ahead of the time event that creates the slime.

There are two ways to fix this, I think, is: 1) Always switch the animation to a different animation at the end of the spit event. 2) Set the animation to not loop,  create the slime based on which frame of the animation is playing. (Use the "Get Current Frame For [Actor]" block under Actors ---> Draw.) This takes estimating the time delay irrelevant altogether.  To do this, put the slime creation block in the "updating" or "drawing" event and use a control Boolean to make sure that it only happens the very first moment that the slime frame occurs. (Set the [Create Slime?] Boolean to "true" at the top of the spit event and then to "false" as soon as the slime has been created in the "updating" event.)

For example, in the "updating" event:

If [Get Current Frame for Actor] = 12    (which starts at 1.2 secs after the animation begins)
         If [Create Slime?] = TRUE
                        [Create {Slime} at X, Y at Front]
                         Set [Create Slime?] = FALSE

« Last Edit: August 07, 2016, 07:39:47 am by BMJ »

KramerGames

  • Posts: 405
Thank you very much! So good to know where this problem was rooted, it was driving me nuts. I went with your first suggestion and stopped looping the animation, I am trying to use as little update events as possible. I added an "switch to animation X" in the "do after 1.5 seconds" block right before the whole event is triggered again. Works perfectly now.
Parasites United  (Idle Parasite Game)

BMJ

  • Posts: 278
OK, glad the first one worked, as it's a little simpler. It's good to limit "update" events, but in this case , the 2nd fix wouldn't be significantly more work for the processor than the first fix, since it's only creating the slime 1 time each spit event. Update events only slow things down when things are actually *done* each frame (creation of actors, complex calculations), not when simply checking attribute values to see if it should do something once. Computers are extremely fast at checking variable values, so you shouldn't be afraid of using the "updating" event as I demonstrated above, if it ever comes in handy (it will). :)