Hi everyone.
I have this simple code and my goal is, when i create the object by clicking on the spawner i will not take off my finger of the screen and i can drag the object to the pipe.
If you can, try it and if you have the solution and can help me, it will be great, Thanks
[code]
function new()
– Librarys
local physics = require “physics”
– Groups
local LocalGroup = display.newGroup()
physics.start()
physics.setGravity( 0, 0 )
local pipe = display.newRect( 150, 0, 20, 80 )
physics.addBody(pipe, “static”, {isSensor = true})
pipe:addEventListener(“collision”, pipe)
function pipe:collision (event)
event.other:removeSelf()
end
local spawner = display.newRect( 140, 400, 40, 40 )
spawner:setFillColor(150, 0, 0)
LocalGroup:insert(spawner)
local function spawnMyObject (event)
if event.phase == “began” then
local myObject = display.newCircle( spawner.x, spawner.y, 25 )
physics.addBody(myObject, “dynamic”)
local function dragObject( event )
local t = event.target
local phase = event.phase
if phase == “began” then
display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if (phase == “moved”) then
event.target.bodyType = “dynamic”
t.x = event.x - t.x0
t.y = event.y - t.y0
myObject.x = t.x
myObject.y = t.y
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
return true
end
myObject:addEventListener(“touch”, dragObject)
end
end
spawner:addEventListener(“touch”, spawnMyObject)
return LocalGroup
end
[/code] [import]uid: 26056 topic_id: 22984 reply_id: 322984[/import]
