1 decade ago by dmarchand
I've spent quite some time getting solid mobile controls down for 2D IOS games (and mobile games in general). This weekend I've open-sourced some of my efforts in this regard, so I figured I'd share them with you guys:
https://github.com/dmarchand/impact-mobile-plugins
There are two plugins here, "touch-joystick" and "touch-joystick-zone"
Touch-Joystick is designed to provide solid analog joystick-style controls for 2D games without having a clunky on-screen controller. On-screen controllers really suck on tablets, as they often require the user to check back and see if they're still keeping their fingers over the controls.
This module lets the user dynamically place the joystick, essentially. When they touch the screen, the initial touch point is logged and stored in the plugin. When they move that same finger around, it updates the delta between the movement position and the origin, and lets you pull it out of the plugin. You can also specify a maximum (real analog sticks only go so far, after all!).
Using it is pretty simple! Call new TouchJoystick(), store a reference to it somewhere useful, and you're good to go! In your update loop, simply check TouchJoystick.delta (has x and y properties), and translate the results to movement in your game!
If you have areas that you don't want to allow the touch to occur in, simply add them via TouchJoystick.addDeadZone(x,y,width,height).
The other plugin is a bit more complicated. It creates a region on the screen that accepts touch motions, essentially. It's useful, for example, if you want to create a box that essentially says "swipe in here to swing your sword". This lets you gain the functionality of multiple sticks without having to bog the user down with really complicated controls.
It's used much like touch-joystick, except that when instantiating it, you pass in the coordinates and size of the area. You may optionally pass in a minimum swipe length value as well, since you probably don't want the player to swing their sword if they simply touch inside the box.
These plugins both work excellently on IOS using Ejecta.
There's still an issue on regular mobile browsers, it seems like the multi-touch doesn't register if you have a TouchJoystick and a TouchJoystickZone. I'm hoping to look at it this week. In the meantime, if anyone sees the cause of it, feel free to let me know!
https://github.com/dmarchand/impact-mobile-plugins
There are two plugins here, "touch-joystick" and "touch-joystick-zone"
Touch-Joystick is designed to provide solid analog joystick-style controls for 2D games without having a clunky on-screen controller. On-screen controllers really suck on tablets, as they often require the user to check back and see if they're still keeping their fingers over the controls.
This module lets the user dynamically place the joystick, essentially. When they touch the screen, the initial touch point is logged and stored in the plugin. When they move that same finger around, it updates the delta between the movement position and the origin, and lets you pull it out of the plugin. You can also specify a maximum (real analog sticks only go so far, after all!).
Using it is pretty simple! Call new TouchJoystick(), store a reference to it somewhere useful, and you're good to go! In your update loop, simply check TouchJoystick.delta (has x and y properties), and translate the results to movement in your game!
If you have areas that you don't want to allow the touch to occur in, simply add them via TouchJoystick.addDeadZone(x,y,width,height).
The other plugin is a bit more complicated. It creates a region on the screen that accepts touch motions, essentially. It's useful, for example, if you want to create a box that essentially says "swipe in here to swing your sword". This lets you gain the functionality of multiple sticks without having to bog the user down with really complicated controls.
It's used much like touch-joystick, except that when instantiating it, you pass in the coordinates and size of the area. You may optionally pass in a minimum swipe length value as well, since you probably don't want the player to swing their sword if they simply touch inside the box.
These plugins both work excellently on IOS using Ejecta.
There's still an issue on regular mobile browsers, it seems like the multi-touch doesn't register if you have a TouchJoystick and a TouchJoystickZone. I'm hoping to look at it this week. In the meantime, if anyone sees the cause of it, feel free to let me know!