Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two sticks in a row #7

Closed
tompe17 opened this issue Mar 2, 2020 · 18 comments
Closed

Two sticks in a row #7

tompe17 opened this issue Mar 2, 2020 · 18 comments
Assignees

Comments

@tompe17
Copy link

tompe17 commented Mar 2, 2020

I am trying to place two sticks in a row. I tried putting them in a table but there is something wrong with the input then since the movements are not correct. I suppose the canvas coordinates might be messed up.

So my question is how can I do what I want to do? It works placing them in div that ends up in two different blocks. Making the divs inline or using span instead of div and it does not work.

@bobboteck
Copy link
Owner

Hi @tompe17 can you send me the HTML you use to reproduce the problem, with the table and other solution you have tested?

@takeru
Copy link

takeru commented Apr 1, 2020

https://jsfiddle.net/ssktkr/2mn5uyae/

Please see right one.

@bobboteck bobboteck self-assigned this Apr 10, 2020
@bobboteck
Copy link
Owner

Hi @takeru and @tompe17 , I see that the problem is related to the use of TABLE tag, that not work correctly with "offset....." properties of elements.
I try to investigate on this problem, alternatively I can suggest to use DIV structure, in this case all work correctly. I commit a new example page as soon as with two JoyStick in one row.

@bobboteck
Copy link
Owner

Ok pushed the example, and you can see in action here http://bobboteck.github.io/joy/joy.html

@tompe17
Copy link
Author

tompe17 commented Apr 10, 2020

Sorry not getting back on this but I did not have my example easily available since I managed to place them after each other in a way that worked in my app. But thanks for the example, I will look at it and see if placing it sidwise works better.

@tompe17
Copy link
Author

tompe17 commented Apr 10, 2020

Looking at your code it seems to be "inline-flex" I missed that it exists. I tried some inline with div but could not get it to work. But good that it works. I liked this code because it was only javascript and no dependencies on big libraries.

@jondurrant
Copy link

On a mobile device the two joysticks won't work together. The second press makes the relevant joystick follow the first press possition.

@liamw9534
Copy link

I'm running into the same problem as @jondurrant. I suspect it is because you are not discriminating the location (X,Y) of the touchstart event. The pressed=1 assignment should only be made for a given JoyStick instance if the (X,Y) happens inside its own canvas area.

@liamw9534
Copy link

Ok, I have a fix for this issue. Replace the onTouchMove function as follows:

        function onTouchMove(event)
        {
                // Prevent the browser from doing its default thing (scroll, zoom)
                event.preventDefault();
                if(pressed==1 && event.targetTouches[0].target == canvas)
                {
      console.log("move:", canvas.id, ":", event);
                        movedX=event.targetTouches[0].pageX;
                        movedY=event.targetTouches[0].pageY;
                        // Manage offset
                        movedX-=canvas.offsetLeft;
                        movedY-=canvas.offsetTop;
                        // Delete canvas
                        context.clearRect(0, 0, canvas.width, canvas.height);
                        // Redraw object
                        drawExternal();
                        drawInternal();
                }
        }

You have to use targetTouches rather than touches.

@liamw9534
Copy link

Sorry, I added in some console.log to the code which you can remove.

@bobboteck
Copy link
Owner

Hi guys, sorry but this days I'm very busy, I hope to work on this issue in the weekend.

@liamw9534 your suggestion is interesting, but I have the doubt that its works whell only if use one JoyStick at time. You have tested a case of simultaneous use of Stick?

@bobboteck bobboteck added the bug label Apr 17, 2020
@bobboteck bobboteck added this to In progress in ISSUE Traking Apr 17, 2020
@liamw9534
Copy link

liamw9534 commented Apr 17, 2020 via email

@bobboteck
Copy link
Owner

Hi @liamw9534 , I try your suggestion on my example page http://bobboteck.github.io/joy/joy.html, but I continue to have the problem with the use of the two simultaneos sticks.
I use Chrome on Android, you?

@liamw9534
Copy link

liamw9534 commented Apr 19, 2020 via email

@liamw9534
Copy link

Hi, the attached test code uses GetX and GetY only which is the only methods I am interested in for my project. Tested using chrome.
joystick.zip

@bobboteck
Copy link
Owner

Thanks @liamw9534 , I was not aware of the change to the next lines, now I have modified the code correctly and it works for me too.
As soon as I have some time to spare, I make changes to the code and publish the new version.
Thanks again for the suggestion!

@liamw9534
Copy link

liamw9534 commented Apr 20, 2020 via email

@bobboteck
Copy link
Owner

Hi @liamw9534 @tompe17 @takeru @jondurrant , I would like if possible to share on the Repository Wiki (even if it is practically empty for now), the projects of those who have used it.
It would be enough to publish a short description, an image, where you can also see the JoyStick, and possibly a link if you have a public repository or a public web page where it is used.
If that's not possible, even a single star to my JoyStick repository is welcome.
Thank you!

@bobboteck bobboteck moved this from In progress to Done in ISSUE Traking Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
ISSUE Traking
  
Done
Development

No branches or pull requests

5 participants