Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

snapshots, coordinates, event coordinates inconsistence
Started by johannes_lalala Nov 15 2013 04:20 AM

No replies to this topic
snapshots touch events
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

johannes_lalala

[GLOBAL: userInfoPane.html]
johannes_lalala
  • Enthusiast

  • 49 posts
  • Corona SDK

Hi all,

 

I'd like to start a little discussion about coronas handling of local coordinate systems and mapping from global to local coordinates.

 

There's a little inconsistence with mapping global coordinates (given by touch events) to local ones:

 

- groups and snapshots have their local coordinate systems centered. Snapshots (having boundaries) always reach from -w/2 to +w/2, and -h/2 to h/2

- ..while the absolute coordinate system defined by touch events and display.getCurrentStage has its zero to the upper left.

 

this often leads to the need of local coordinate transformation where it wouldn't really be needed.

 

For instance if we are to write a simple paint program, we would probably use a fullscreen snapshot as painting canvas. In order to have the whole snapshot visible, we'd center it on the screen. Now if we want to draw something we always have to map the coordinate of the event to the local coordinate of the snapshot (which is off by w/2, h/2).

 

Same thing if we want to assemble our background (the one that doesn't change) to a snapshot texture and forget the stuff we added to reduce memory consumption. And often, we will find ourselves registering a touch listener to that background, so again we have to map the coordinates nontrivially.

 

When we used groups for that in graphics 1.0 this wasn't so bad, because groups don't have boundaries and we could just leave them at absolute 0, 0 and map coordinates by identity. With snapshots this is not possible.

 

I think the last example will be a very common thing and one should consider giving us some convienience tools for coordinate localization. I know there's Object.contentToLocal, but this is a bit clumsy: events are tables with x and y entries while contentToLocal returns x,y. We will often end up writing something like

 

lx, ly = event.target:contentToLocal (event.x, event.y)

locTouch = {x=lx, y=ly}

 

A perhaps better approach would be having event entries holding the local coordinates with respect to the event target.

 

Even better: the possibility of setting the local zero of something in relation to its anchor point.

 

Or one can think about removing the inconsistence for good by centering the global coordinate system on the screen, or choose, where it is. (I'd love that:)).

 

I think now would be a good time for that, as we will experience some api disruption either way..

 

regards,

Johannes




[topic_controls]
[/topic_controls]