PrimaryFeather/Starling-Framework — Issue #72: Excess (unnecessary) transformation of touch position
Author: fljot
Created: 2012-03-08 10:10:51+00:00
State: open

*I'm personally think it's a bug. And as this place is suitable for discussions, I decided not to put this into Starling forum, but rather discuss right here*

So there's this code in starling.core::Starling class (onTouch method): https://github.com/PrimaryFeather/Starling-Framework/blob/master/starling/src/starling/core/Starling.as
```
// move position into viewport bounds
globalX = mStage.stageWidth * (globalX - mViewPort.x) / mViewPort.width;
globalY = mStage.stageHeight * (globalY - mViewPort.y) / mViewPort.height;
```
which later becomes Touch#globalX/globalY and, of course, affects how Touch#getLocation() works. I think it's totally unnecessary and bad for two reasons:

1. Conceptually global coordinates stand for exactly GLOBAL coordinates. The only global we have is stage coordinates. Analog for native display list: if you transform your root (scale or rotate) then in some touch/mouse event stageX and stageY will still be global (in stage scope), not somehow magically converted according to root transformation.

2. Using these coordinates for touch tracking and gesture recognition. All the gesture recognition must be done using touches' global coordinates because this is how we interact with our physical touch surface.
Example: Let's say we have typical touch scrolling. In common case we never start to scroll right away on the first finger movement because we might accidentally move finger a bit while we actually perform tap (click). So imagine we have transformed Starling viewport now, let's say scaled up twice. So this "slop" (min distance we need to move to begin pan gesture recognition and begin scrolling) will become twice larger! Which is not a good for UX since we have exactly the same physical screen and we use our fingers in exactly same old manner. But UI magically start to behave differently (imho worse in any case).

Don't forget that removing this transformation affects calculation of Touch#getLocation and DisplayObjectContainer#hitTest methods. Which won't make you happy for sure=) But really read carefully and try to understand.

* I'm not a Starling user yet, just inspecting the code since I'm adjusting my gesture recognizing library to work also with Starling. So maybe I miss something?