britzl / defold-input

Simplify input related operations such as gesture detection, input mapping and clicking/dragging game objects
MIT License
111 stars 26 forks source link

iOS onscreen controls: action.x / action.y are always 0 on button release #39

Closed lharder closed 6 months ago

lharder commented 6 months ago

There seems to be a problem with the onscreen controls: the x/y position of a touch is not reported correctly upon releasing a button. The action/touch event that is propagated looks e.g. like this:

{ 
  id = hash: [button_a],
  x = 0,
  y = 0,
  released = true,
  pressed = false
}

x and y are always 0, no matter where the touch occurred. To me, it looks like the problem is in onscreen.lua, lines 34 and 35:

local function create_data(control)
        local data = {
            x = control.x or 0,
            y = control.y or 0,
            id = control.id,
            pressed = control.pressed,
            released = control.released,
        }
        return data
    end 

Upon button release, the parameter "control" passed into the function does not contain "x" and "y". Instead it has an object "control.touch_position" with properties "x" and "y", so that this change seems to fix the problem (although I do not know the code well enough to know about possible side effects):

x = control.x or control.touch_position.x or 0,
y = control.y or control.touch_position.y or 0,
britzl commented 6 months ago

You're right. It looks like control.touch_position.x should be used if available. I've made that change now.