Anyways, here's a video demonstrating it:
To load and use it, simply require the "andralog" file as you'd do with any other. Next, assemble a variable to it:
Code: Select all
myAnalog = newAnalog(x, y, r, b, d) --'x' is the analog's center x --'y' is the analog's center y --'r' is the analog's radius --'b' is the button/stick radius --'d' is the analog's deadzone. Varies from 0 to 1, 0 being no deadzone and 1 being whole analog as deadzone
myAnalog.update(dt) on love.update
myAnalog.draw() on love.draw
myAnalog.touchPressed(id, x, y, dx, dy, pressure) on love.touchPressed
myAnalog.touchReleased(id, x, y, dx, dy, pressure) on love.touchReleased
myAnalog.touchMoved(id, x, y, dx, dy, pressure) on love.touchMoved
And these are the variables that you can change after you've created your analog:
myAnalog.spring - If true, the analog stick returns to the center after being released. If false, stays in place and retains movement output. Defaults to true.
myAnalog.reclick - If true, you can catch the stick after being released before it reaches the center (with spring on). If false, the stick can only be grabbed again once it reaches the center. Defaults to true.
myAnalog.limitedRange - If true, doesn't change the stick's angle if you move it further than its effect radius. If false, moves it around as if it was being moved within its effect radius. Defaults to false.
myAnalog.rangeRelease - If true, releases the stick once you move it further than its effect radius (with spring on). If false, continues taking actions based on the previous setting. Defaults to false.
myAnalog.pressure - Defines the minimum pressure based on the sensitivity of the touchscreen required to move the stick. Some touchscreens don't have pressure sensitivity, so its value is set to 1. Defaults to 0.5.
myAnalog.releaseSpeed - Defines the time (in seconds) it takes for the stick to reach the center once released (with spring on). Defaults to 0.2.
You can always replace the draw function to whatever you prefer. The one I did includes 3 functions I wrote to make it fancy, so you're free to use those as well, which I'm publishing on the "Small Useful Functions" thread (which SURPRISE, it's mine too ).
Last, but not least, the functions you can use to get info about the controls:
myAnalog.getX() - returns a number from -1 to 1 regarding the stick's horizontal direction
myAnalog.getY() - returns a number from -1 to 1 regarding the stick's vertical direction
myAnalog.isHeld() - returns true or false about whether or not the stick is being held
I'm including a download to the video's example as well, so you can experiment a bit. It was made specifically for LÖVE Android, but I made a quick converter from mouse input to touch controls. Also, this library should support having two or more analogs working individually of each other, even though people will rarely even use 2 analogs.
[attachment=0]Andralog Example_10.love - For LÖVE 0.10.x![/attachment] [attachment=1]andralog.lua - For LÖVE 0.10.x![/attachment]