corona icon indicating copy to clipboard operation
corona copied to clipboard

[Core]: Touch event xDelta and yDelta are incorrect

Open XeduR opened this issue 4 years ago • 0 comments

xDelta and yDelta properties were added to touch event in https://github.com/coronalabs/corona/commit/68e90cbdafb50c07be5b850c13fc02f8d75e5c9c, however, they were implemented incorrectly.

The documentation pages for xDelta and yDelta have example codes that only work if the the device/window dimensions are identical to those of config.lua.

The reason is that these delta values are both scaled by Solar2D and then rounded to the nearest integer (neither of which should be happening).

For example, if you have a config.lua content area of 480x320 and you run the simulator on a 960x640 device, then the scale factor will be 2. This means that when you drag a touch event by 10 pixels, this gets multiplied by 2, to 20. Or if you simulate a 1920x1080 device, then the scale factor will be 1.6875, so the 10 pixels gets scaled to 16.875, which then gets rounded to 17.

The real problem occurs when Solar2D also scales the display object movements, so if you have a 480x320 content area and you drag a display object by 10 pixels on a 960x640 display, then the delta values get scaled to 20 and then the display object movement gets scaled again to 40, resulting in double scaling/movement.

Currently, you can obtain the correct delta values by:

xDeltaReal = event.x - event.xStart
yDeltaReal = event.y - event.yStart

In summary:

  • event.xDelta and event.yDelta values are being rounded, which should not happen.
  • event.xDelta and event.yDelta values are being dynamically scaled, which should not happen.

XeduR avatar Aug 10 '21 06:08 XeduR