This is my code that spawns new objects:
Below it is some code given to me by Danny. The bottom code works great and I sorta understand how it works. However, I can’t seem to incorporate his code with mine. Basically, I’m trying to move my object(s) from one spot to another by first clicking on it and then clicking on a different area. ( The second code shows what I’m talking about). Any help would be appreciated.
My code*************************************************
local function spawnDisk( event )
local phase = event.phase
if “ended” == phase then
audio.play( popSound )
randImage = diskGfx[math.random( 1, 4 )]
allDisks[#allDisks + 1] = display.newImage( randImage )
local disk = allDisks[#allDisks]
disk.x = 60
disk.y = 50
disk.xScale = 1.8; disk.yScale = 0.8
transition.to(disk, { time = 500, xScale = 1.0, yScale = 1.0, transition = easingx.easeOutElastic })
physics.addBody( disk, { density=0.5, friction=0.9, radius=20.0, bounce=0.2 } )
disk.linearDamping = 0.4
disk.angularDamping = 0.6
disk:addEventListener( “touch”, dragBody )
end
return true
end
pipe:addEventListener( “touch”, spawnDisk ) – touch the red disk to spawn objects
Runtime:addEventListener( “enterFrame”, removeOffscreenItems )
Code from other member****************************************
local myObject = display.newRect(100, 100, 50, 50)
local targetToMove = nil
local function setTarget(event)
local target = event.target
targetToMove = target
return true
end
myObject:addEventListener(“tap”, setTarget)
local function moveObject(event)
if targetToMove ~= nil then
targetToMove.x = event.x
targetToMove.y = event.y
targetToMove = nil
end
return true
end
Runtime:addEventListener(“tap”, moveObject)
[import]uid: 127842 topic_id: 22391 reply_id: 322391[/import]
