Hello all,
it’s possible when i create a Image and add event listener touch. dispatch it?
this, don’t work:
obj= display.newImage(“levels/1.png”)
obj:addEventListener(“touch”,onTouch)
obj:dispatchEvent({name=touch,phase=‘began’, target=obj })
the touch event drag my object to touch position
this is the touch function
local function onTouch(event)
local t=event.target
local phase =event.phase
if “began” == phase then
local parent =t.parent
parent:insert(t)
display.getCurrentStage():setFocus(t)
t.x0=event.x-t.x
t.y0=event.y-t.y
elseif “moved” == phase then
t.x = event.x-t.x0
t.y = event.y-t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus (ni)
t.isFocus =false
end
return true
end
i will start drag the object when i created.
Thanks all!