wait for animation to finish

213 views
Skip to first unread message

Mark

unread,
Sep 26, 2014, 5:14:26 AM9/26/14
to haxe...@googlegroups.com
hi Guys,

Another day, another issue :) All and any help is appreciated! Thank you in advance!


What I'd like to do is, waiting for an animation to finish, before execution of caller's code goes on. Something like:

[main.hx]
myAnim
.playAnim(); //Anim.hx
//when done, ie after playAnim returned:
myMenu
.Show(); //or addChild(myMenu);, etc



The goal is not to show myMenu on stage, and not even load until animation of myAnim is complete.

myAnim.playAnim is (e.g.) doing an actuate tween (but could do anything else. like playing another kind of animation, or a music video, etc, so 'Actuate' here doesn't really matter, it's just easy to add):
Actuate.tween(fadeBMP, 1, { alpha: 0 });
Actuate.tween(fadeBMP, 1, { alpha: 1 }).repeat(1).reflect(); //fade in, fade out


If I try to Sys.sleep(x); everything "freezes" (ie all application-related queues and event loops are suspended).
If I try to work with an .onComplete() flag(bool) - and while (!flag) {  }, that's even worse (eternal loop).
What I need is something like doEvents in Windows:
Actuate.....
Actuate.....onComplete(setDoneFlag);
while (!animOver) {
   doEvents
();
}
return; //playAnim() function is over, ie animation is done. playAnim() gives back
       
//control to parent, "myMenu.Show();" get's executed there


The goal is, to let the animation play out, then give back drive from playAnim() function. In other words making the animation a "synchronous call".

Thank you again!

Cristian Baluta

unread,
Sep 26, 2014, 6:23:15 AM9/26/14
to haxe...@googlegroups.com
onComplete is a function that is called when the animation finishes, how are you trying to use it?
When you run the while loop nothing else works because you're blocking the thread. Flash will let you know after 15seconds, other targets i don't know how they handle it. Most of the targets don't have multiple threads but that loop is still the worst thing ever even if you don't block the  main thread.

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.



--

Mark

unread,
Sep 26, 2014, 6:30:00 AM9/26/14
to haxe...@googlegroups.com
like I wrote, I want to use it like this:


[main.hx]
myAnim
.playAnim(); //Anim.hx
//when done, ie after playAnim returned:
myMenu
.Show(); //or addChild(myMenu);, etc

instead of having an onComplete callback, I want to wait for the animation to finish, and do nothing in the mean time

wighawag

unread,
Sep 26, 2014, 6:42:21 AM9/26/14
to haxe...@googlegroups.com
You could have a look at the following library : https://github.com/Atry/haxe-continuation
I did not use it myself but it basically allow you to do what you want (using some metadata) and internally it will convert your code to use callbacks via macros)

Cristian Baluta

unread,
Sep 26, 2014, 7:20:55 AM9/26/14
to haxe...@googlegroups.com
why not code properly from the beginning?

Axel Huizinga

unread,
Sep 26, 2014, 7:41:10 AM9/26/14
to haxe...@googlegroups.com

Am 26.09.2014 13:20, schrieb Cristian Baluta:
why not code properly from the beginning?

On Fri, Sep 26, 2014 at 1:41 PM, wighawag <wigh...@gmail.com> wrote:
You could have a look at the following library : https://github.com/Atry/haxe-continuation
I did not use it myself but it basically allow you to do what you want (using some metadata) and internally it will convert your code to use callbacks via macros)


On Fri, Sep 26, 2014 at 11:30 AM, Mark <markk...@gmail.com> wrote:
like I wrote, I want to use it like this:

[main.hx]
myAnim
.playAnim(); //Anim.hx
//when done, ie after playAnim returned:
myMenu
.Show(); //or addChild(myMenu);, etc

instead of having an onComplete callback, I want to wait for the animation to finish, and do nothing in the mean time
Am I missing something? I expected the onComplete callback exactly to do what you want?

Mark

unread,
Sep 26, 2014, 9:07:26 AM9/26/14
to haxe...@googlegroups.com
wighawag: Just what I need, thank you for the help!

Axel: No it's not,  wighawag's answer was the proper one. What I need is to wait/yield/doevents for an animation, start to end until it finishes, then "go on with the action" in my app. onComplete is async.



---- OFF ----
To the smart guy knowing everything about "proper coding":
I assume you never worked with anything but flash and browser... maybe mobile... so telling you as FYI an environment's limitation does not necessarily means the exact and only right way of coding "by the will of gods"...
For flash, which actually is living in a safe and distant bubble far away from everything where one can cause any trouble -by improperly coding-, giving up application's processing time really is something pointless - so it was not implemented.

My case, however is slightly different. Haxe is not flash. Desktop is not a browser or mobile. And believe it or not, there is a good reason behind openGL, .NET (or even the oldie VB from MS), JAVA, C, C++, etc - so basically most high level languages and environments to support yielding/"doevents-like" actions.

So this is a lack of feature which needs workaround at the moment, until e.g. Haxe or openFL or whatever provides a solution, and definitely not a wrong way of coding...

Cristian Baluta

unread,
Sep 26, 2014, 2:12:12 PM9/26/14
to haxe...@googlegroups.com
As i see it, the right way of coding is what the language can do, so maybe you can use untyped on the targets that can do what you want. 

Nathan Hüsken

unread,
Sep 26, 2014, 2:24:18 PM9/26/14
to haxe...@googlegroups.com

Just to provide another perspective.

I do the following:
I like to use Furtures (from tink_core). So I have a “monax” monad for Futures, that does exactly this:
Wait for a future to finish, than call the function that returns the next one wait for it to finish e.t.c.

This has the advantage, that when of the “time taking” actions return a value, I can pass it to others in a convenient way.

Why futures? Because I think they are more convenient, but it could also be done with callbacks. Of course, all tween elements must be converted to Futures, so if you only have tweens than I would use callbacks (or in case of actuate IGeneralActuator) as it removes this extra step.

So in kind of pseudo-code it looks like this:

FutureUtils.hx:

class FutureUtils {
  static public function toFuture(actuator : IGeneralActuator) : Future<Noise> {
     ...
  }
}

Then I do:

  FutureMonad.Do({
    doSomeAnimation().toFuture();
    value <= someOtherFutureReturningAction():
    doMoreAnimation().toFuture();
    doValueDependingAnimation(value).toFuture();
    ...
  });

Now, this might overkill for your case. Just wanted to throw it in.
And of course I am happy to provide more detail if needed …

Regards,
Nathan

Reply all
Reply to author
Forward
0 new messages