i try to test touch events (on Android platform) and found big delay between finger moves and touchmoved events.
I think 1) there is some gap inside sdl-love2d or 2) love.touchmoved happens too frequently with little delta or 3) i make mistake inside my code
[youtube]https://www.youtube.com/watch?v=_NrupVLSSiA[/youtube]
My test code
Code: Select all
function love.conf(t)
t.window.vsync = false
end
function love.load(arg)
local font = love.graphics.newFont(25)
love.graphics.setFont(font)
end
function love.keypressed(key,scancode,isrepeat)
if key == "escape" then
love.event.quit(0)
end
end
local touches = {}
function love.draw()
local x, y, dx, dy
for _, data in pairs(touches) do
if data then
x, y, dx, dy = unpack(data)
love.graphics.setLineWidth(5)
love.graphics.setColor(255,255,255)
love.graphics.circle("line", x, y,100)
love.graphics.setColor(255,0,0)
love.graphics.circle("line", x + dx or 0, y + dy or 0, 120)
end
end
love.graphics.setColor(255,255,255)
love.graphics.print("FPS: "..tostring(love.timer.getFPS( )), 10, 10)
love.graphics.print("Time: "..tostring(love.timer.getAverageDelta()), 10, 30)
end
-- I need normal id of the touch, not system int64 aka "userdata 0x00000002"
function parse_touch_id(id)
-- str_id = tostring(id)
-- if string.sub(str_id, -4) == "NULL" then
-- return "a00"
-- else
-- return "a" .. string.sub(str_id, -2)
-- end
return tostring(id)
end
function love.touchpressed(id, x, y, dx, dy, pressure)
local key = parse_touch_id(id)
touches[key] = { x, y, dx, dy }
end
function love.touchmoved( id, x, y, dx, dy, pressure )
local key = parse_touch_id(id)
touches[key] = { x, y, dx, dy }
end
function love.touchreleased( id, x, y, dx, dy )
local key = parse_touch_id(id)
touches[key] = nil
end