jeremyc Posted October 18, 2014 Share Posted October 18, 2014 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); }; Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted October 19, 2014 Share Posted October 19, 2014 Hi Jeremy, Could you edit your post inside tag code. It's really more easy to read. Sam Carlos R 1 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted October 19, 2014 Share Posted October 19, 2014 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. Quote Link to comment Share on other sites More sharing options...
jeremyc Posted October 19, 2014 Author Share Posted October 19, 2014 Thanks a million guys. 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.