bobboteck / JoyStick

A simple JoyStick that use HTML5, Canvas and Vanilla JavaScript, for touch and mouse interfaces (no JQuery required), preview at:
https://bobboteck.github.io/joy/joy.html
MIT License
365 stars 98 forks source link

Size scalability not working properly #9

Closed oliverruoff closed 4 years ago

oliverruoff commented 4 years ago

When changing the div sizes (width / height) to e.g. 600x600, the Joystick gets too big, thus cannot be moved further than X=20 and Y=20. This is due to a hardcoded number ("50") in the .js code in the calculation for the internalRadius variable. Maybe you could consider changing the calculation to something more generous.

Here you can see how I fixed it for my project: https://github.com/vanslipon/JoyStick/blob/vanslipon-patch-1/joy.js I simply changed the line: var internalRadius = (canvas.width-((50*2)+10))/2; to var internalRadius = (canvas.width-(((canvas.width/4)*2)+10))/2;

Like this, the joystick circle scales completely fine and everything works as expected again, since other variables like externalRadius are using the internalRadius.

Nevertheless, very nice code and good work! Thx for the cool Joystick :) I'm also using it to control my robot.

Greetings from germany and stay healthy!

bobboteck commented 4 years ago

@vanslipon thanks for the suggestion and to appreciate the project.

I would like to suggest you further code optimization: var internalRadius = (canvas.width-((canvas.width/2)+10))/2;

Staying healthy in this period is fundamental, I wish it to you too! Thanks again for the report