Interface coding - how to get the coordinates of the screen area tapped with a finger.

Hi everyone,

I am working on my first game using Corona. I would like to learn how to make a display object move to an area of the screen that the user just tapped. I am guessing the procedure would be, tap the display object first so it gets focus, tap an area of the screen and get its coordinates, then transition the display object to said coordinates? (transforms?).

Suggestions and code snippets appreciated! I am currently experimenting with the sample found here http://developer.anscamobile.com/content/drag-me-multitouch

Thanks,
Lloyd [import]uid: 52069 topic_id: 12029 reply_id: 312029[/import]

Heya lloyd :slight_smile:

This should help you start, although will need modifying. (Your object is called “ball” for this example.)

[lua]local background = display.newImage(“background.png”)

local ball = display.newImage(“ball.png”)
ball.x = 100
ball.y = 50

local function moveBall (event)
ball.x = event.x
ball.y = event.y
end

background:addEventListener(“tap”, moveBall)[/lua]

That’s instant; if you want it gradual change the function to include a transition :slight_smile:

Peach [import]uid: 52491 topic_id: 12029 reply_id: 44016[/import]

Hey Peach,

Thanks a lot for giving me a start. This is awesome, turned the shapes into physics bodies and some interesting things can be done.

Cheers :slight_smile:
Lloyd [import]uid: 52069 topic_id: 12029 reply_id: 44033[/import]