Jump to content

character control


chroms3
 Share

Recommended Posts

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?

 

 

 

Link to comment
Share on other sites

<!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.

08-2.png

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...