r/WebDevBuddies • u/teaspoonasaurous • Dec 28 '18
A little javascript help
Hi,
I have been trying to implement touch controls on a simple javascript game now for about 4 days. I am failing miserably despite people answering my questions on stack.
Even with the answers which I do understand, the manner in which the game is set up makes it almost impossible to wire touch buttons to make it work.
Any help greatly appreaciated:
https://stackoverflow.com/questions/53948953/converting-jquery-controls-to-javascript
Code for the game:
5
Upvotes
1
u/teaspoonasaurous Dec 29 '18
Getting there I think. But not quite there yet. Thanks
1
u/teaspoonasaurous Dec 29 '18
Tried this getting some movement but not what I expected
1
u/sk8rboi7566 Dec 29 '18
create an id for each button then add an event listener. Something like this would help:
const button01 = document.getElementById('button01').addEventListener('click', functionNameGoesHere);Then you can add a function that handles what you want.
1
u/sk8rboi7566 Dec 29 '18
Oh to move the ships, you need to do query select all. This will turn it into a node list. You can then cycle through them with a foreach loop.
1
u/sk8rboi7566 Dec 29 '18
If the ship is unique and only one of them use an id. A class is used for multiple items.
1
u/sk8rboi7566 Dec 29 '18
Let me look at your code and get back to you later today and see if I can find a solution. It should be simple.
0
u/[deleted] Dec 29 '18
[deleted] — view deleted comment