I am building some demos and i want o move some fruits only to the right, i saw this demo on the corona website
local function onTouch( event )
local t = event.target
-- Print info about the event. For actual production code, you should
-- not call this function because it wastes CPU resources.
printTouch(event)
local phase = event.phase
if "began" == phase then
-- Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
-- Spurious events can be sent to the target, e.g. the user presses
-- elsewhere on the screen and then moves the finger over the target.
-- To prevent this, we add this flag. Only when it's true will "move"
-- events be sent to the target.
t.isFocus = true
-- Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if "moved" == phase then
-- Make object move (we subtract t.x0,t.y0 so that moves are
-- relative to initial grab point, rather than object "snapping").
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif "ended" == phase or "cancelled" == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
-- Important to return true. This tells the system that the event
-- should not be propagated to listeners of any objects underneath.
return true
end
the full code, to try is here:
http://developer.anscamobile.com/content/drag-me
my goal is only to drag to the right direction i know that i need to change the t.x variable but i dont know how i can do to only drag to the right, if anyone know this little issue and can help will be great for me.
Thanks people [import]uid: 26056 topic_id: 23327 reply_id: 323327[/import]
[import]uid: 26056 topic_id: 23327 reply_id: 93513[/import]