Page 1 of 1

New API in love-native-android

Posted: Thu Sep 06, 2012 9:30 pm
by Moe
Multitouch

Code: Select all

function love.touchpressed(x, y, i)
Called when one or more user presses on the screen.
Parameters:
x: Array/List with all x parameters
y: Array/List with all y parameters
i: Index of event that triggered the event; 0 if this feature is not supported

Code: Select all

function love.touchreleased(x, y, i)
Called when one or more user stop touching the screen.
Parameters:
x: Array/List with all x parameters
y: Array/List with all y parameters
i: Index of event that triggered the event; 0 if this feature is not supported

Code: Select all

function love.touchmove(x, y, i)
Called when one or more user move over the screen.
Parameters:
x: Array/List with all x parameters
y: Array/List with all y parameters
i: Index of event that triggered the event; 0 if this feature is not supported

Sensors:
Sensors do a nice Android live cycle and disable if the screen turns off or if the user quits the application. This is to reduce power consumption.

Code: Select all

function love.sensor.enable(s)
Enable a sensor.
Parameter:
s: Name of the sensor, possible values are any sensor values from Android according to your Android version. Please use the name as string, e.g. "TYPE_ALL".

Code: Select all

function love.sensor.disable(s)
Disable a sensor.
Parameter:
s: Name of the sensor, possible values are any sensor values from Android according to your Android version. Please use the name as string, e.g. "TYPE_ALL".

Code: Select all

function love.sensorchanged(n,t,v)
Called in case of a sensor event. You need to activate sensors by calling love.sensor.activate!
Parameters:
n: Name of the sensor (String).
t: Type of the sensor (String) according to Android sensor names.
v: Values according to the sensor type. Provided as float array.

Example Touch:

Code: Select all

function love.touchpressed(x, y, i)
    print("love.touchpressed", i)
    print("x")
    for index,val in pairs(x) do
      print(index, "->", val)
    end
    print("y")
    for index,val in pairs(y) do
      print(index, "->", val)
    end
end

function love.touchreleased(x, y, i)
    print("love.touchreleased", i)
    print("x")
    for index,val in pairs(x) do
      print(index, "->", val)
    end
    print("y")
    for index,val in pairs(y) do
      print(index, "->", val)
    end
end

function love.touchmove(x, y, i)
    print("love.touchmove", i)
    print("x")
    for index,val in pairs(x) do
      print(index, "->", val)
    end
    print("y")
    for index,val in pairs(y) do
      print(index, "->", val)
    end
end
Example Sensors:

Code: Select all

function love.load()
  love.sensor.enable("TYPE_ALL")
end

function love.sensorchanged(n,t,v)
    print(n, t)
    for index, val in pairs(v) do
      print(index, "->", val)
    end
end

Re: New API in love-native-android

Posted: Fri Sep 07, 2012 5:47 am
by T-Bone
Testable version of the example in the post above:

Re: New API in love-native-android

Posted: Fri Sep 07, 2012 10:40 am
by Robin
Looks cool, but:
Moe wrote:add 1 to convert to Lua index
May I ask why that is not done automatically?

Re: New API in love-native-android

Posted: Fri Sep 07, 2012 3:48 pm
by Moe
Because I forgot about it and saw it when I wrote the documentation - and when I had done all commits and uploads. This will change when I figured out why my device returns always the first finger - as long as we see this behaviour, this info is useless anyway, besides it returns something else on someone's device...
Since T-Bone was waiting for this update, I did not want to delay it.
So this is actually a known bug, but this is just a WIP snapshot anyway...

Re: New API in love-native-android

Posted: Sun Sep 09, 2012 1:07 pm
by T-Bone
It's not that big of a hurry, but thanks a lot for caring about me :) I appreciate it :neko:

Re: New API in love-native-android

Posted: Thu Sep 20, 2012 11:06 pm
by Moe
API change:
- Touch-Event-ID is now Lua-like.
- Added sensor API.