html5-virtual-game-controller icon indicating copy to clipboard operation
html5-virtual-game-controller copied to clipboard

How to use joystick data

Open OmeGaCinoS opened this issue 11 years ago • 2 comments

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

OmeGaCinoS avatar Feb 12 '14 22:02 OmeGaCinoS

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

KarlWang avatar Oct 30 '14 01:10 KarlWang

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.

ApoorvSaxena avatar Nov 22 '14 21:11 ApoorvSaxena