|
@ -94,9 +94,17 @@ if (haveEvents) { |
|
|
setInterval(scangamepads, 500); |
|
|
setInterval(scangamepads, 500); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var joystick_axes = { |
|
|
|
|
|
x1: 0, |
|
|
|
|
|
y1: 0, |
|
|
|
|
|
x2: 0, |
|
|
|
|
|
y2: 0, |
|
|
|
|
|
moved: false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Virtual Joystick
|
|
|
// Virtual Joystick
|
|
|
var joystick = nipplejs.create({ |
|
|
var joystick = nipplejs.create({ |
|
|
zone: document.getElementById('controls'), |
|
|
zone: document.getElementById('controls_l'), |
|
|
mode: 'static', |
|
|
mode: 'static', |
|
|
//catchDistance: 150,
|
|
|
//catchDistance: 150,
|
|
|
position: {left: '50%', top: '50%'}, |
|
|
position: {left: '50%', top: '50%'}, |
|
@ -104,21 +112,33 @@ if (haveEvents) { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
joystick.on('move', function(evt, data) { |
|
|
joystick.on('move', function(evt, data) { |
|
|
console.log(data.vector); |
|
|
joystick_axes.x1 = data.vector.x; |
|
|
|
|
|
joystick_axes.y1 = data.vector.y; |
|
|
|
|
|
joystick_axes.moved = true; |
|
|
}); |
|
|
}); |
|
|
/* |
|
|
|
|
|
|
|
|
var joystick2 = nipplejs.create({ |
|
|
|
|
|
zone: document.getElementById('controls_r'), |
|
|
|
|
|
mode: 'static', |
|
|
|
|
|
//catchDistance: 150,
|
|
|
|
|
|
position: {left: '50%', top: '50%'}, |
|
|
|
|
|
color: 'red' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
joystick2.on('move', function(evt, data) { |
|
|
|
|
|
joystick_axes.x2 = data.vector.x; |
|
|
|
|
|
joystick_axes.y2 = data.vector.y; |
|
|
|
|
|
joystick_axes.moved = true; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setInterval(function(){ |
|
|
setInterval(function(){ |
|
|
if (joystick) { |
|
|
if (joystick_axes.moved) { |
|
|
if (joystick._pressed === true || joystick2._pressed === true) { |
|
|
gp_socket.emit('axes', {0: joystick_axes.x1, 1: joystick_axes.y1, 3: joystick_axes.x2, 4: joystick_axes.y2}); |
|
|
var dx = joystick.deltaX() / joystick._stickRadius; |
|
|
joystick_axes.moved = false; |
|
|
var dy = joystick.deltaY() / joystick._stickRadius; |
|
|
|
|
|
var dx2 = joystick2.deltaX() / joystick2._stickRadius; |
|
|
|
|
|
var dy2 = joystick2.deltaY() / joystick2._stickRadius; |
|
|
|
|
|
gp_socket.emit('axes', {0: dx, 1: dy, 3: dx2, 4: dy2}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
}, 50); |
|
|
}, 50); |
|
|
*/ |
|
|
|
|
|
window.addEventListener("orientationchange", function(event) { |
|
|
window.addEventListener("orientationchange", function(event) { |
|
|
//joystick._updatePositionOfContainer();
|
|
|
//joystick._updatePositionOfContainer();
|
|
|
//joystick2._updatePositionOfContainer();
|
|
|
//joystick2._updatePositionOfContainer();
|
|
|