Can someone clarify the difference between these? And how would I use these to click and drag an object in a scaled display group? [import]uid: 54716 topic_id: 10755 reply_id: 310755[/import]
Lets say you have a big display group called ‘rect’ at (50,50) with respect to the origin of the screen (aka content, it’s the top left).
You want to insert a circle called ‘circ’ into rect to the point you touch on rect.
So let’s say you touch the screen at (100, 100). The event variables event.x and event.y of that touch event would be (100, 100).
Now you think all I have to do is
circ = display.newCirc(rect, e.x, e.y, width, height)
That won’t work! It’ll put circ at (100, 100) relative to the rect’s reference point (which by default is rect’s top left corner) which is actually (150, 150) relative to the top left of the screen (aka content).
So here’s what you actually have to do:
localX, localY = rect:contentToLocal(e.x, e.y) --localX and localY = 50
circ = display.newCirc(rect, localX, localY, width, height)
That code will put circ at (50, 50) relative to rect and (100, 100) relative to content.
Now you can apply the same logic to dragging an object if it’s in a display group that is at a random point on the screen.
Hope that helps! [import]uid: 49205 topic_id: 10755 reply_id: 39091[/import]
Thanks [import]uid: 54716 topic_id: 10755 reply_id: 39106[/import]