MarianG Posted June 17, 2015 Share Posted June 17, 2015 Hi guys, I have another little problem. Unfortunately I can't share too much code, but i 'll try to synthesize. I have a park with 7,8 animals, all animals have plenty animations like, from key 0 to 100 - walk animation, 110-180- run, etc. When I load all animals, I try to start for each of them one animation, random from the entire film.But animation start only for 3 or 4, when one is finished, start another animation, and so on, but after a few time the animations stop at a time.And the others animals nothing do.If i refresh the page, 3 other animals will be animated, and the others nothing, and so on.I test the animations foreach individual animals, and works fine, but when I import more than 3 or 4 diferent animals the animation not start at all. And all animals have the same skeleton. And I can't explain why. And a piece of code:BABYLON.SceneLoader.ImportMesh("",url,"lion.babylon", scene, function (m, p, s) { m[0].active_animation = 1; m[0].skeleton = s[0]; var on_end = function(){ //stop actual animation scene.stopAnimation(m[0].skeleton, setting[m[0].active_animation].from, setting[m[0].active_animation].to, false,1); //choose one animation random from film m[0].active_animation = parseInt((Math.random() * 10) + 1); //start new animation scene.beginAnimation(m[0].skeleton, setting[m[0].active_animation].from, setting[m[0].active_animation].to, false,1,on_end); } scene.beginAnimation(m[0].skeleton, setting[m[0].active_animation].from, setting[m[0].active_animation].to, false,1,on_end);});Thanks a lot, and sorry my bad english. Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 18, 2015 Share Posted June 18, 2015 Hi, would be great to have this reproduced on the playground to be able to debug this. Can you try adding a bit mroe of the original code to playground? A quick note about your code - Calling the function at the end of the animation is explicitly running it after the animation stopped. So there is no reason to call stopAnimation. In the same matter - stopAnimation takes only one parameter (target) and is anyhow called when executing begingAnimation (https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/babylon.scene.ts#L679) , so this is redundant. But I doubt this is the problem... Quote Link to comment Share on other sites More sharing options...
MarianG Posted June 18, 2015 Author Share Posted June 18, 2015 Hi, RaananW. I finally found the problem, but I don't know if is a bug, or I is a problem in my code. Here are solution: BABYLON.SceneLoader.ImportMesh("",url,"lion.babylon", scene, function (m, p, s) {m[0].active_animation = 1;m[0].skeleton = s[0]; m[0].anim_fin = false;var on_end = function(){ m[0].anim_fin = true;}var check = setInterval(function(){ if(m[0].anim_fin){ m[0].active_animation = parseInt((Math.random() * 10) + 1); scene.beginAnimation(m[0].skeleton, setting[m[0].active_animation].from, setting[m[0].active_animation].to, false,1,on_end); m[0].anim_fin = false; }},200)scene.beginAnimation(m[0].skeleton, setting[m[0].active_animation].from, setting[m[0].active_animation].to, false,1,on_end); });And now, I'll try to explain the problem. It enters the "on_end" function various times, at the end of one animation, not just once. I started an animation, it finishes and then enters the function "on_end" 3,4 times, not only one time, for each animation, then again in the function several times and so on until all the animations get blocked. I make a playground, but there work fine, u can see that in console.http://www.babylonjs-playground.com/#1HUCSD Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 18, 2015 Share Posted June 18, 2015 With wich version of babylon are you working ? It was a bug in 2.0 that I fixed in 2.1 if I remember correctly. Quote Link to comment Share on other sites More sharing options...
MarianG Posted June 18, 2015 Author Share Posted June 18, 2015 i still use babylon2.0. I'll try with 2.1 and i'll tell you the difference. Thanks. Quote Link to comment Share on other sites More sharing options...
MarianG Posted June 23, 2015 Author Share Posted June 23, 2015 Hi Tenechon, I update my babylonjs version to 2.1 and now it works fine, without setInterval, and other updates,... now it enters on the "on_end" function only one time. Thanks for your help. GameMonetize 1 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.