Hazardus Posted September 28, 2015 Share Posted September 28, 2015 I'm having a little trouble with actions, animations, and callbacks. It looks like there isn't a native way to accomplish what I'm after, but I wanted to check with the experts before I continue. What I'm trying to accomplish: I want to execute an action which fires a function (callback) before and after the animation. I can accomplish the "before" callback by creating using CombineAction, but it appears the onAnimationEnd is out of my scope.. Specifically in this 1st case I've encountered, I'm using the InterpolateValueAction - which appears to create an Animation for me (while giving me no option to inject the onAnimationEnd callback). I looked around in Animatable but it doesn't seem like it is what I need either. I thought maybe I could access the animations array of the mesh but alas, it's empty until the action is invoked. Is there a native way I'm missing? Quote Link to comment Share on other sites More sharing options...
iiceman Posted September 28, 2015 Share Posted September 28, 2015 Hey Hazardus, a playground would be nice so that everbyody know what and how exactly you want to do it. InterpolateValueAction doesn't seem to have a callback function for animation end, but I know scene.beginAnimation has it: http://doc.babylonjs.com/tutorials/07._Animations#parameters-for-scenebeginanimationhttp://doc.babylonjs.com/classes/2.2/Scene#beginanimation-target-from-to-loop-speedratio-onanimationend-animatable-rarr-animatable-classes-2-2-animatable- Maybe there is another way to achieve what you want while using beginAnimation (maybe with the ExecuteCodeAction)? Anyhow, a playground that shows what you have so far might greatly help Quote Link to comment Share on other sites More sharing options...
Hazardus Posted September 29, 2015 Author Share Posted September 29, 2015 Sure. Here is what I have so far: http://www.babylonjs-playground.com/#2JO9B Quote Link to comment Share on other sites More sharing options...
iiceman Posted September 29, 2015 Share Posted September 29, 2015 Okay, you could do something like that: http://www.babylonjs-playground.com/#2JO9B#1 This uses the ExecuteCodeAction and is some more code than you had before, but seems to work. Maybe somebody else has a better idea or knows how to do the same with less code (maybe with using the InterpolateValueAction). Let me know if that helped Quote Link to comment Share on other sites More sharing options...
Hazardus Posted September 29, 2015 Author Share Posted September 29, 2015 Hmm.. I like it! I suppose InterpolateValueAction is the only one that has duration (except maybe playSoundAction), and the rest are instant (start/stop = same point in time). It gives more control over the Animation itself, which is also a plus. Being able to pass a callback would be nice, but this is much better than what I was (reluctantly) considering: modifying the native function or using a Timeout. Thanks, iiceman! Quote Link to comment Share on other sites More sharing options...
iiceman Posted September 29, 2015 Share Posted September 29, 2015 You are welcome Don't forget to show us what you created when you are done! By the way: if it answers your question you can flag the thread as answered, too. Quote Link to comment Share on other sites More sharing options...
Hazardus Posted September 29, 2015 Author Share Posted September 29, 2015 You are welcome Don't forget to show us what you created when you are done! By the way: if it answers your question you can flag the thread as answered, too. Sure - it will be a while longer before I can, but I'll definitely share this neat little project when it's done! By the way.. the "Animatable" page in the docs leads to a 404 (which I love - "working on my machine" hehehe). From what I gather it's rarely used and just happens to be in the source code, but I'd love to know for sure when/how/why to use this. ( the link: http://doc.babylonjs.com/tutorials/page.php?p=25171 ) Quote Link to comment Share on other sites More sharing options...
iiceman Posted September 30, 2015 Share Posted September 30, 2015 Where did you find that link? I somehow can't find it... or did somebody already fix this? Quote Link to comment Share on other sites More sharing options...
Temechon Posted September 30, 2015 Share Posted September 30, 2015 Here is the correct link : http://doc.babylonjs.com/classes/2.2/Animatable Quote Link to comment Share on other sites More sharing options...
iiceman Posted September 30, 2015 Share Posted September 30, 2015 I just realized that the interpolateValueAction uses beginDirectAnimation wich is pretty much the same as beginAnimation (they both can have that needed callback). So it would be easy to add a callback parameter to the interpolateValueAction, right? Or is there a reason that the interpolateValueAction didn't get that callback parameter? (note to myself: learn typescript to be able to create pull requests for those simple things that even I could do to get my name on the contributor list ) Quote Link to comment Share on other sites More sharing options...
Hazardus Posted October 1, 2015 Author Share Posted October 1, 2015 is there a reason that the interpolateValueAction didn't get that callback parameter? I wondered that myself. The same goes for BABYLON.Animation.CreateAndStartAnimation - why not 1 more parameter for simplicity? Getting to that much needed onAnimationEnd is a bit of a hassle, though as Ice pointed out it can be done. As for where I found the link, it's actually on the http://doc.babylonjs.com/tutorials/07._Animations page under ( Parameters for scene.beginAnimation ). I couldn't seem to find a way to edit the docs and fix it myself. I was really hoping the link would be a doc page. I've checked out Animatable in the classes section and the source code, but it's still a bit of a mystery to me. I haven't had a chance to mess around with it just yet. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 1, 2015 Share Posted October 1, 2015 Hello here is the doc to update the doc :http://www.html5gamedevs.com/topic/16365-contributing-to-documentation-101/ Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 1, 2015 Share Posted October 1, 2015 And BOOOM New constructor for InterpolateAction:constructor(triggerOptions: any, target: any, public propertyPath: string, public value: any, public duration: number = 1000, condition?: Condition, public stopOtherAnimations?: boolean, public onInterpolationDone?: () => void) { new signature for CreateAndStartAnimation:public static CreateAndStartAnimation(name: string, mesh: AbstractMesh, targetProperty: string, framePerSecond: number, totalFrame: number, from: any, to: any, loopMode?: number, easingFunction?: EasingFunction, onAnimationEnd?: () => void) Hazardus and iiceman 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.