zouarino Posted November 30, 2014 Share Posted November 30, 2014 I have a problem. when I press the button, the animation doesn't loop.please help my. var createScene = function () { var scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 8, 50, BABYLON.Vector3.Zero(), scene); camera.attachControl(canvas, false); var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene); BABYLON.SceneLoader.ImportMesh("Cube", "scenes/", "x.babylon", scene, function (newMeshes) { scene.stopAnimation(newMeshes[0]); // On push on a touch...window.addEventListener('keydown',function(event){ if (event.keyCode == 65){ scene.beginAnimation(newMeshes[0], 40, 60, true); } }); // On push off a touch...window.addEventListener('keyup',function(event){if (event.keyCode == 65){ scene.stopAnimation(newMeshes[0]);}); }); return scene;} Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 1, 2014 Share Posted December 1, 2014 Hey could you share this on the playground? that's far easier for me to debug! Quote Link to comment Share on other sites More sharing options...
zouarino Posted December 3, 2014 Author Share Posted December 3, 2014 this is the source files http://www.mediafire.com/download/x1l6zro7c78ww1p/exp2.rar Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 4, 2014 Share Posted December 4, 2014 I prefer a repro case using playground please Quote Link to comment Share on other sites More sharing options...
Mimetis Posted December 4, 2014 Share Posted December 4, 2014 Hi; First of all, as Deltakosh said, a quick repo in the Playground would be more flexible and an easy way to debug your case.btw, your problem comes from your implementation of the "addeventlistener". Mesh doesn't support such method. Here is a quick solution, where I used the pointerdown and pointerup event attached on the canvas, and the scene.pick() method to know if we clicked the correct mesh, or not : Seb aka Mimetis// Get the canvas element from our HTML belowvar canvas = document.getElementById("renderCanvas");// Load the BABYLON 3D enginevar engine = new BABYLON.Engine(canvas, true);var meshAnimation = undefined;// -------------------------------------------------------------var createScene = function () { var scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 8, 50, BABYLON.Vector3.Zero(), scene); camera.attachControl(canvas, false); var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene); BABYLON.SceneLoader.ImportMesh("Cube", "/scenes/", "x.babylon", scene, function (newMeshes) { meshAnimation = newMeshes[0]; scene.stopAnimation(meshAnimation); }, function (scene) { console.log(scene.toString()); }); return scene;}// -------------------------------------------------------------var onPointerDown = function (evt) { if (evt.button !== 0 || meshAnimation === undefined) { return; } // check if we are under a mesh var pickInfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return mesh === meshAnimation; }); if (pickInfo.hit) { scene.beginAnimation(meshAnimation, 40, 60, true); }}var onPointerUp = function () { if (meshAnimation === undefined) { return; } // check if we are under a mesh var pickInfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return mesh === meshAnimation; }); if (pickInfo.hit) { scene.stopAnimation(meshAnimation); }}canvas.addEventListener("pointerdown", onPointerDown, false);canvas.addEventListener("pointerup", onPointerUp, false);// Now, call the createScene function that you just finished creatingvar scene = createScene();scene.onDispose = function () { canvas.removeEventListener("pointerdown", onPointerDown); canvas.removeEventListener("pointerup", onPointerUp);}// Register a render loop to repeatedly render the sceneengine.runRenderLoop(function () { scene.render();});// Watch for browser/canvas resize eventswindow.addEventListener("resize", function () { engine.resize();}); 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.