Bug in dx/dy for multi touch on Android (DEF-1726)(SOLVEDx3)

“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.

My output from a bugged entry:
DEBUG:SCRIPT: touch result:
DEBUG:SCRIPT: pprint: {
“x” = 519.75006103516
"screen_dx" = 0
“pressed” = false
“y” = 741.60003662109
“screen_y” = 464
“acc_y” = -0.52083331346512
“acc_x” = 0.084722220897675
“screen_dy” = 0
“acc_z” = -0.86944442987442
"screen_x" = 346
“dx” = 0
“value” = 1
“repeated” = false
“released” = false
“dy” = 0
}

DEBUG:SCRIPT: multi_touch result:
DEBUG:SCRIPT: pprint: {
"screen_dx" = 1
“x” = 519.75006103516
“touch” = [table: 0x58280650]
{
1 = [table: 0x58280690]
{
“x” = 519
“tap_count” = 0
“pressed” = false
“y” = 741
“dx” = 1
“released” = false
“dy” = 1
}
}
“pressed” = false
“y” = 741.60003662109
“screen_y” = 464
“acc_y” = -0.52083331346512
“acc_x” = 0.084722220897675
“screen_dy” = 1
“acc_z” = -0.86944442987442
"screen_x" = 346
“dx” = 1.5000001192093
“value” = 1
“repeated” = false
“released” = false
“dy” = 1.5999999046326
}

3 Likes

Thank you for reporting! This issue is already in our backlog (DEF-1726). Please get back to me about its criticality.

2 Likes

I’m not actually sure that it is the same bug, since DEF-1726 refers to multiple fingers and my repro case only involves one finger?

1 Like

I will extend this issue with your post, thanks

1 Like

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?

@agulev is this something you recognise? Can you please create a ticket if we don’t have one?

1 Like

This issue marked as solved in our bug track system.
Could you please share a project with a minimal reproduce case?

What do you mean locally and on Android? Are you talking about apk bundle?

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.

Okay, here is a very simple example. I was going to record it on Android, but couldn’t find a way to show the actual key presses.

AndroidMultitouch.zip (200.8 KB)

I see one problem and one potential problem:

  1. 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.
  2. 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.

Behold! A video showing the issue:

Help!

Did you try to do the same (as on video) with sprite?
It looks like an issue with the coordinate conversion from input to GUI mode, not with dx/dy.

Nope, just tried it on a GUI. It’s for a virtual controller, so perfect to use GUI for it!

But hang on a second, isn’t this a Very Common Use Case ™? Surely it’s not a Defold issue?

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:

Or check @britzl 's example virtual gamepad here:

2 Likes

Great stuff, thanks!

Ps. Screen coordinates vs. adjust modes will to me always be a mystery. :slight_smile:

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

Are you sure you added changes into your render_script?

1 Like

I am sure I didn’t! Thanks for the gotcha, now it works. Here is the test project in all it’s working glory:

AndroidMultitouch.zip (111.7 KB)

Thanks for the help @AGulev!

4 Likes