Help with touch

Ok so i have a prototype project, mostly to learn both Lua and Corona SDK.
Its a little Air Hokey style game:

Background (not movable just static)
then i will have a ball and a usr controlled puck and a cpu one.

Now i tried following the Follow ME Example but not having much success, so i wanna better understand how to assign control over the puck (user)?

here is my small code soo far

–test b

local backgroud = display.newImage( “BACK.png” )
local usr = display.newImage( “usr.png” )
usr.x = display.stageWidth / 2
usr.y = display.stageHeight - 50

function usr:touch( event )
end

usr:addEventListener( “touch”, usr )
function usr:touch( event )

end
usr:addEventListener( “touch”, usr )
Anyone can help me out? Usr is the player puck image that will be moved by the player. I have only added the back image and the usr untill i get this to work :slight_smile:
Thank you in advance
[import]uid: 6061 topic_id: 816 reply_id: 300816[/import]

Hi ct,

i have to go to work now, but will look at it when I have time tonight. In about 15 hours.

Cheers
Michael [import]uid: 5712 topic_id: 816 reply_id: 1770[/import]

Ok here you go…

–test b
local backgroud = display.newImage( “BACK.png” )
local usr = display.newImage( “usr.png” )
usr.x = display.stageWidth / 2
usr.y = display.stageHeight - 50

function usr:touch( event )
if event.phase == “began” then
–print(“began”)
display.getCurrentStage():setFocus( usr )
elseif event.phase == “moved” then
usr.x = event.x
usr.y = event.y
elseif event.phase == “ended” or event.phase == “cancelled” then
–print(“ended”)
display.getCurrentStage():setFocus( nil )
end
end
usr:addEventListener( “touch”, usr )

This is one way of doing it, but there are so many variations. Does this hel you? [import]uid: 5712 topic_id: 816 reply_id: 1775[/import]

Oh man, thank you thank u!!! Works a charm! Wow
I understood a bit from the code in the follow me ex, but because it started dealing with 3 objects and actually creating them vs using your own, i got lost.
Thank you soo much for your time, i really appreciate, now i can carry forth and figure out the rest. You just made my DAY!!! [import]uid: 6061 topic_id: 816 reply_id: 1777[/import]

You’re welcome! [import]uid: 5712 topic_id: 816 reply_id: 1784[/import]

Nice Post… Thanks… [import]uid: 4527 topic_id: 816 reply_id: 2625[/import]