Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Help with touch
Started by coronatest Apr 18 2010 09:32 AM

- - - - -
5 replies to this topic
[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

coronatest

[GLOBAL: userInfoPane.html]
coronatest
  • Observer

  • 9 posts
  • Guests

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 :)
Thank you in advance
uid: 6061 topic_id: 816 reply_id: 300816


[TOPIC: post.html]
#2

MikeHart

[GLOBAL: userInfoPane.html]
MikeHart
  • Corona Geek

  • 1,278 posts
  • Corona SDK

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
uid: 5712 topic_id: 816 reply_id: 1770


[TOPIC: post.html]
#3

MikeHart

[GLOBAL: userInfoPane.html]
MikeHart
  • Corona Geek

  • 1,278 posts
  • Corona SDK

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?
uid: 5712 topic_id: 816 reply_id: 1775


[TOPIC: post.html]
#4

coronatest

[GLOBAL: userInfoPane.html]
coronatest
  • Observer

  • 9 posts
  • Guests

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!!!
uid: 6061 topic_id: 816 reply_id: 1777


[TOPIC: post.html]
#5

MikeHart

[GLOBAL: userInfoPane.html]
MikeHart
  • Corona Geek

  • 1,278 posts
  • Corona SDK

You're welcome!
uid: 5712 topic_id: 816 reply_id: 1784


[TOPIC: post.html]
#6

webmail

[GLOBAL: userInfoPane.html]
webmail
  • Observer

  • 18 posts
  • Corona SDK

Nice Post.... Thanks..
uid: 4527 topic_id: 816 reply_id: 2625



[topic_controls]
[/topic_controls]