Very slow love.touchmoved

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
roller
Prole
Posts: 1
Joined: Sun Aug 14, 2016 8:05 pm

Very slow love.touchmoved

Post by roller »

Hi,

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
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Very slow love.touchmoved

Post by pgimeno »

Note the FPS is 60. That's because love.conf isn't in a separate conf.lua file. I get a similar delay with the mouse (after adapting your program). After properly disabling vsync, it works fine.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Very slow love.touchmoved

Post by zorg »

To add to this, you can specify the function that's usually in a conf.lua file inside main.lua, but the function only sets the fields inside the function to the given parameter; you'll need to set everything manually yourself (and this won't stop löve from creating a default window, and everything else either, also you can't disable modules after they have been loaded by default.) It's easier to just do it how you're supposed to.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests