New API in love-native-android

A project to port LÖVE to Android handhelds
Locked
Moe
Party member
Posts: 115
Joined: Thu Dec 22, 2011 10:20 pm

New API in love-native-android

Post 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
Last edited by Moe on Thu Sep 20, 2012 11:05 pm, edited 1 time in total.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: New API in love-native-android

Post by T-Bone »

Testable version of the example in the post above:
Attachments
mt.love
(2.28 KiB) Downloaded 521 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: New API in love-native-android

Post by Robin »

Looks cool, but:
Moe wrote:add 1 to convert to Lua index
May I ask why that is not done automatically?
Help us help you: attach a .love.
Moe
Party member
Posts: 115
Joined: Thu Dec 22, 2011 10:20 pm

Re: New API in love-native-android

Post 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...
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: New API in love-native-android

Post by T-Bone »

It's not that big of a hurry, but thanks a lot for caring about me :) I appreciate it :neko:
Moe
Party member
Posts: 115
Joined: Thu Dec 22, 2011 10:20 pm

Re: New API in love-native-android

Post by Moe »

API change:
- Touch-Event-ID is now Lua-like.
- Added sensor API.
Locked

Who is online

Users browsing this forum: No registered users and 29 guests