chroms3 Posted March 9, 2016 Share Posted March 9, 2016 Hello. I can not understand the character configuration management. Character moves forward by means of "w" key. I along with "w" press and release "space". triggered event "keyup" and the event is "keydown" reset how to fix this problem? Make it so that the event "keydown" will not be reset? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 10, 2016 Share Posted March 10, 2016 Hello, Try to see the source code of the demo I'm doing here. this can help you. http://www.babylon.actifgames.com/Survival/index.php Quote Link to comment Share on other sites More sharing options...
chroms3 Posted March 10, 2016 Author Share Posted March 10, 2016 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Гейм</title> <script type="text/javascript" src="http://cdn.babylonjs.com/2-3/babylon.js"></script> <script type="text/javascript" src="hand-1.3.7.js"></script> <script type="text/javascript" src="cannon.min.js"></script> </head> <body> <canvas id="canvas" style="position:absolute; width: 100%; height: 100%;"></canvas> <script type="text/javascript"> var canvas = document.getElementById("canvas"); var engine = new BABYLON.Engine(canvas, true); var player; var keyPlayer; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! window.onkeyup = function (event) { if (event.keyCode == 32) { player.playAnimation(22, 32, false, 100); } else { player.stopAnimation(); player.cellIndex = 44; keyPlayer = ""; } } window.onkeydown = function (event) { if (event.keyCode == 65 && keyPlayer != event.keyCode) { player.playAnimation(0, 9, true, 100); } keyPlayer = event.keyCode; } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! function createScene() { var scene = new BABYLON.Scene(engine); scene.clearColor = new BABYLON.Color3(0, 1, 1); var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene); camera.setTarget(BABYLON.Vector3.Zero()); camera.attachControl(canvas, false); var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene); light.intensity = .5; var spriteManagerTrees = new BABYLON.SpriteManager("treesManagr", "08-2.png", 2, 64, scene); player = new BABYLON.Sprite("player", spriteManagerTrees); player.cellIndex = 44; return scene; }; var scene = createScene(); engine.runRenderLoop(function () { scene.render(); }); window.addEventListener("resize", function () { engine.resize(); }); </script> </body> </html> Here is the code that controls the 2d sprite. Quote Link to comment Share on other sites More sharing options...
chroms3 Posted March 10, 2016 Author Share Posted March 10, 2016 So I did not wait for an answer and wrote a script that controls your character . I would be grateful if you are familiar with it and improve it. I hope it will be useful to you . 2d game control.zip 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.