Browse Source

enable joysticks

main
Hendrik Langer 4 years ago
parent
commit
be562204aa
  1. 44
      raspberry/roberto/views/frontend/templates/gamepad.js
  2. 14
      raspberry/roberto/views/frontend/templates/index.html

44
raspberry/roberto/views/frontend/templates/gamepad.js

@ -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();

14
raspberry/roberto/views/frontend/templates/index.html

@ -19,12 +19,19 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
#controls { #controls_l {
position: absolute; position: absolute;
bottom: 40px; bottom: 40px;
left: 0; left: 0;
width: 50%;
height: 33%;
pointer-events: all;
}
#controls_r {
position: absolute;
bottom: 40px;
right: 0; right: 0;
width: 100%; width: 50%;
height: 33%; height: 33%;
pointer-events: all; pointer-events: all;
} }
@ -58,7 +65,8 @@
<div id="video"> <div id="video">
<video id="stream" autoplay playsinline muted controls>Your browser does not support video</video> <video id="stream" autoplay playsinline muted controls>Your browser does not support video</video>
<canvas id="textoverlay"></canvas> <canvas id="textoverlay"></canvas>
<div id="controls"></div> <div id="controls_l"></div>
<div id="controls_r"></div>
</div> </div>
<form id="message" method="POST" action='#'> <form id="message" method="POST" action='#'>
<input type="text" name="message_data" id="message_data" placeholder="Message"> <input type="text" name="message_data" id="message_data" placeholder="Message">

Loading…
Cancel
Save