“touch” and “multi_touch” seems to be different in regards to dx/dy and screen_dx/dy as the multi_touch version seems to be wrong in some cases.
Repro steps:
function on_input(self, action_id, action)
if action_id == hash("touch") then
print("touch result: ")
pprint(action)
end
if action_id == hash("multi_touch") then
print("multi_touch result: ")
pprint(action)
end
end
Output will differ if you press one finger on the screen and move it slightly and then hold in steady in one place. This was reproduced with a Samsung Galaxy S2.
I bumped into this bug today, which makes a virtual controller behave erratically because dx and dy appear to be incorrect on Android. It works when testing it locally.
Has there been a fix for this, or is it workaround time?
Sure, will knock one up. May be my code then if it’s already fixed!
Locally: Running on the dev PC’s player (not sure what the terminology is here!)
Remotely: Immediate testing on an Andriod device with the runtime player installed.
action.screen_x and action.screen_y are way off on Android. If you tap the lower left corner at 0,0 it appears to work, but anywhere else gets exponentially worse.
action.screen_dx and action.screen_dy seems to gradually become more inaccurate when dragging, but hard to prove this because of 1.
Local IDE player works as expected. Is it my code that causes it to misbehave on Android, or something else?
Update 1: Using action.x and action.y works better on Android, but action.y and action.dy get offset the further you are from the center of the screen. This is likely to have caused the original issue with the virtual controllers that rely on the input being accurate.
The issue only seems to happen when using “Adjust mode: Fit” and “Strech” (for stretch the y axis is fine, but the x axis is gradually more offset the closer to the edge you get); when using “Zoom” on the node it works as intended.
Update 2: After a lot of faffing, I managed to get the runtime onto iOS. It displays the same issue.
Can someone explain where I’m going wrong? It’s unlikely it’s an issue with Defold because it’s such a fundamental problem.
Yes, it’s not a bug on Defold side. You just need to to use screen coordinates (screen_x, screen_y) and convert them to you adjust mode using this module, for example:
So, I’ve come to using this module and I’m not sure how! I get screen coordinates from input, but then what? This doesn’t work (the node is moved outside the screen area):
local screen_pos = vector3(action.screen_x,action.screen_y,0)
gui.set_screen_position(pie, screen_pos)
I also tested the virtual gamepad, but it suffers from the same offset issue when run on device. There is some commented out code in there, maybe @britzl was going to add it but never did?
function on_input(self, action_id, action)
local ratio_x = action.x / (action.screen_x or action.x)
local ratio_y = action.y / (action.screen_y or action.y)
if action.touch then
for i,tp in pairs(action.touch) do
--tp.x = tp.x / ratio_x
--tp.y = tp.y / ratio_y
handle_touch(self, tp, i)
end
else
handle_touch(self, action, 0)
end
end