jeromeetienne / virtualjoystick.js

a virtual joystick library to emulate a joystick on touch screen in javascript
http://jeromeetienne.github.com/virtualjoystick.js/examples/basic.html
MIT License
419 stars 125 forks source link

How does fire button work ? #28

Open warpdesign opened 10 years ago

warpdesign commented 10 years ago

Reading the issues, it appears a fire button should appear when touching the right of the screen. The thing is when touching the right of the screen, the joystick appears and not the fire button.

I'm initializing virtualjoystick like this:

joystick = this.joystick = new VirtualJoystick({ container : document.getElementsByClassName('main')[0], mouseSupport : true, });

Is there anything else to do to have the firebutton ? How do I listen for firebutton presses ? Is there an equivalent to joystick.left() ? Maybe joystick.fire() ?

Thanks for the help.

ssugar commented 8 years ago

There isn't a built in fire button. You need to create a second joystick, constrain it's stick radius to 0, and use the touchstart event listener to detect touch events on that joystick. In that touchstart event listener, you'd then add whatever code you have to fire whatever you're looking to fire.

Look at https://github.com/jeromeetienne/virtualjoystick.js/blob/master/examples/dual.html to get a start on this.