austinhallock / html5-virtual-game-controller

An easy-to-implement, customizable virtual game controller for HTML5 games
MIT License
333 stars 63 forks source link

How to use joystick data #6

Open OmeGaCinoS opened 10 years ago

OmeGaCinoS commented 10 years ago

Hello!

I found your virtual game controller and I try to put in, in my game but... I can't even use it because I dun understand how to use the joystick.

I just wanna know where I can have joystick position, etc,

Thanks

KarlWang commented 9 years ago

Same question here. Could you please offer some simple examples? Cheers!

ApoorvSaxena commented 9 years ago

The example code listed in README is incorrect. Here's the correct example to configure joystick:

GameController.init( { 
    left: {
        type: 'joystick', 
        position: { left: '15%', bottom: '15%' },
        joystick: {
          touchStart: function() {
            console.log('touch starts');
          },
          touchEnd: function() {
            console.log('touch ends');
          },
          touchMove: function( details ) {
            console.log( details.dx );
            console.log( details.dy );
            console.log( details.max );
            console.log( details.normalizedX );
            console.log( details.normalizedY );
          }
        }
    }, 
    right: { 
        type: 'joystick', 
        position: { right: '15%', bottom: '15%' } ,
        joystick: {
          touchMove: function( details ) {
             // Do something...
           }
       }
    }
});

Please note, that you have to enclose touchStart, touchEnd and touchMove functions inside joystick object. I would suggest you to read Advanced Options Section carefully.