Jump to content

Animation end callback fuction


Recommended Posts

I've been trying to add a animation end callback function to David Rousset's very handy animateCameraPositionAndRotation function http://blogs.msdn.co...babylon-js.aspx but I can't seem to get a animation end callback to work. The camera animation works great but at the end of it nothing happens.  


I'm trying to use "isStopped" but I just can't get it to fire when the animation ends. I'm not even sure I'm barking up the right tree. And to be honest my javascript understanding of object methods and event listeners is marginal.  


Ive tried


1. if (animCamRotation.isStopped()) { alert('stopped'); } (inside the animateCameraPositionAndRotation function)


2. if (animCamRotation.isStopped()) { alert('stopped'); } (inside the engine.runRenderLoop)


3. And a few others that broke the script entirely


Am I in the balpark at all?



Here is the function

         var animateCameraPositionAndRotation = function (freeCamera, fromPosition, toPosition,                                                             fromRotation, toRotation) {                            var animCamPosition = new BABYLON.Animation("animCam", "position", 30,                                          BABYLON.Animation.ANIMATIONTYPE_VECTOR3,                                          BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);                            var keysPosition = [];                keysPosition.push({                    frame: 0,                    value: fromPosition                });                keysPosition.push({                    frame: 10,                    value: toPosition                });                            animCamPosition.setKeys(keysPosition);                            animCamRotation = new BABYLON.Animation("animCam", "rotation", 30,                                          BABYLON.Animation.ANIMATIONTYPE_VECTOR3,                                          BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);                            var keysRotation = [];                keysRotation.push({                    frame: 0,                    value: fromRotation                });                keysRotation.push({                    frame: 10,                    value: toRotation                });                            animCamRotation.setKeys(keysRotation);                freeCamera.animations.push(animCamPosition);                freeCamera.animations.push(animCamRotation);                                                        scene.beginAnimation(freeCamera, 0, 10, false);                        };
Link to comment
Share on other sites

I am sorry, but I do not read Javascript, only Typescript.  Looking at babylon.scene.ts the call signature for beginAnimation is:

public beginAnimation(target: any, from: number, to: number, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void, animatable?: Animatable): Animatable {

The last line of your example calls this, but does not specify past the loop argument.  If you added a speedRatio, and an onAnimationEnd function, then put any code you want in that function.  When the animation ends this should be called.  


I am sure isStopped() works perfectly, it is just that its purpose is for outside code to test when it is done using polling, not executing code on completion.

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...