Comments (2)
first, there is a bug, when i change the view, the old stuff remains, this is because the line
var all_views = document.querySelectorAll('view');
must be
var all_views = document.querySelectorAll('div.view');
and second, i found two solutions for this problem
with two separated joysticks for every mode
in the html
var joy;
var joy1;
var joy2;
in the main app in the html
joy1 = new JoyStick('joyDiv');
joy = joy1;
this.airconsole.onMessage = function(from, data) {
if (data.view) {
showView(data.view);
if (joy2 == null)
joy2 = new JoyStick('joyDiv2');
if (joy == joy1)
joy = joy2;
else
joy = joy1;
}
}
in body
<div id="ingame_attack" class="view">
<div id="pass-button" ontouchstart="window.app.sendMessageToScreen('pass')"></div>
<div id="shoot-button" ontouchstart="window.app.sendMessageToScreen('shoot')"></div>
<div id="joyDiv"></div>
</div>
<div id="ingame_defense" class="view">
<div id="change-button" ontouchstart="window.app.sendMessageToScreen('pass')"></div>
<div id="tackle-button" ontouchstart="window.app.sendMessageToScreen('shoot')"></div>
<div id="joyDiv2"></div>
</div>
with a separated div for joystick
in body
<div id="ingame_attack" class="view">
<div id="pass-button" ontouchstart="window.app.sendMessageToScreen('pass')"></div>
<div id="shoot-button" ontouchstart="window.app.sendMessageToScreen('shoot')"></div>
</div>
<div id="ingame_defense" class="view">
<div id="change-button" ontouchstart="window.app.sendMessageToScreen('pass')"></div>
<div id="tackle-button" ontouchstart="window.app.sendMessageToScreen('shoot')"></div>
</div>
<div id="ingame_joystick" class="view">
<div id="joyDiv"></div>
</div>
in html, in the funcion show view
var showView = function (id) {
var view = document.getElementById(id);
var all_views = document.querySelectorAll('div.view');
// Hide all containers
for (var i = 0; i < all_views.length; i++) {
all_views[i].style.display = 'none';
}
// Show container
view.style.display = 'block';
document.getElementById('ingame_joystick').style.display = 'block';
};
from joystick.
Sorry @hawkpurpletree, but I don't understand the problem.
What I can tell you is that if you have to use multiple JoySticks on the page, you must assign each DIV that will contain the JoyStick, a different ID, as you can also see on the example page [https://github.com/bobboteck/JoyStick/blob /master/joy.html].
You could call them Joy1 and Joy2, or to be clearer in your scope code, JoyAttack and JoyDefense.
However if you want to ask a few more questions, you can also use the GitHub Discussions that I have activated and found here [https://github.com/bobboteck/JoyStick/discussions], instead of using the Issues.
If you are interested, I recently published the project as an NPM package.
To close, I would be very curious to see your finished project, to see how you used the JoyStick, then if you want there is a Wiki page where I have published some projects that use it, and if it is possible for you I would like to add yours too.
from joystick.
Related Issues (20)
- Issues with position: absolute; HOT 4
- Issues with position: fixed; in CSS(again) HOT 9
- More robust calculation of touch/click position relative to canvas HOT 3
- Integration in third-party application HOT 3
- 4 directions HOT 7
- Joystick Stays At Position When Cursor Let Go Outside of Joystick HOT 5
- Allow AddListener/Callback HOT 4
- Add one dimensional joysticks (X or Y axis) HOT 4
- The joystick does not move to the left (moves to the right) after I add position: fixed; top: 0; to the CSS grid div CSS (HTML provided) HOT 5
- Every time I move the Joystick on Chrome on Android I get joy.js:163 [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/5093566007214080 HOT 4
- Issue with multiple joysticks
- x and y coordinates outside the range of (-100, 100)
- Provide a reset or recenter function
- Hosting on GitHub Pages would be helpful HOT 2
- When using large non-square width and heights (especially width) the joystick has very little movement in one axis
- No integrated direction buttons?
- Doesnโt Scale if elements are % (or vw/vh)
- Touch mode not activating in Chrome HOT 1
- Bug when working with two joysticks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from joystick.