Zino54220 Posted April 9, 2014 Share Posted April 9, 2014 Hi gentlemen! I need your help again! I would like play a mesh's animation with keyboard event. (I precise that the mesh is imported from Blender...) If I press my keyboard touch one time, I have this : You can see that my (bad) animation is correctly played... It's cool) But if I press in continue the touch, I have this : You can see here that the animation is "stopped" and restart if I push off the touch (the touche is push off when the mouse cursor move on the seconde .gif) So you understand my problem! If I want translate a mesh and animate it in the same time (like to make a walk animation for example) I must repair this bug! I use the window.addEventListener('keydown') and ('keyup') to manage keyboard. Here a example code :// On push on a touch...window.addEventListener('keydown',function(event){if (event.keyCode == codeToucheAvance){ scene.beginAnimation(skeleton[0],80,100); // Add true change nothing...}});// On push off a touch...window.addEventListener('keyup',function(event){if (event.keyCode == codeToucheAvance){ scene.stopAnimation();//This line in comment change nothing... }});The animation begin in the keydown event because in the scene.registerBeforerender(), the animation plays only when I push off the keyboard touch... Thanks you for your help! Zino Quote Link to comment Share on other sites More sharing options...
Artem Posted April 9, 2014 Share Posted April 9, 2014 var animationStated = false; function startAnimation() { if (!animationStarted) { animationStarted = true; scene.beginAnimation(skeleton[0],80,100); } }Then run the function when you press the button and when the button is up set 'animationStarted' to 'false' there. Quote Link to comment Share on other sites More sharing options...
Zino54220 Posted April 9, 2014 Author Share Posted April 9, 2014 Thanks you Artem! I will see your solution as soon as possible and will inform you Quote Link to comment Share on other sites More sharing options...
Zino54220 Posted April 9, 2014 Author Share Posted April 9, 2014 The solution is good in part Artem! (and don't worry, I saw the missing "r" ) Now I would like this animation plays in continu while I press the key... I add the parameter "true" in "scene.beginAnimation(skeleton[0],80,100,true)" but if the button is up, the animation continue to plays... So I look to create a new function like yours, call "duringAnimation" for example and which reload the animation if it finished... In your opinion, it's a good way or not? Thanks your for your help! Quote Link to comment Share on other sites More sharing options...
Artem Posted April 10, 2014 Share Posted April 10, 2014 You're welcome. I don't know, but I think anything is good enough if it works as you want in result I'm a noob to programming, so I just tried to help and give an idea of how to do it (since I used quite the same logic for my own game). I'd love to see how your thing will turn out. Good luck, Zino54220! Quote Link to comment Share on other sites More sharing options...
Zino54220 Posted April 10, 2014 Author Share Posted April 10, 2014 Ok Artem ! Your idea solved my first problem so I'll put this topic on "Solved" and I'll work an algo to my second problem and if the result is good, I'll post it. Quote Link to comment Share on other sites More sharing options...
Zino54220 Posted April 14, 2014 Author Share Posted April 14, 2014 So gentlement! I complete my post! Thanks to Artem, the main problem (which was stay with the key pressed blocked the skeleton-animation) is resolved and to make a animation in continu (like to make a walk animation with an armature for an example...), I went in bad and complicate solution... And with this (very good) documentation : http://doc.babylonjs.com/page.php?p=24646 I realised that I can simply make this :// In the 'keydown' AddEventListener...if(!animationStarted){ scene.beginAnimation(skeletons[0], 45, 60,true,1.0,function(){animationStarted = false;}); animationStarted = true;}// In the 'keyup' AddEventListener...scene.stopAnimation(skeletons[0]); animationStarted = false;And I have a little result like this : (Of course it's a test ) If I press the key in continu, the skeleton animation plays normaly from the beginning at the end and if I press the key many times, the skeleton animation do again from the beginning (like you can see in the middle of the gif's animation when I made many press on the key) ! So thanks you Artem and believe in your project gentlemen! Zino 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.