Hi! I’m new to corona and programming in general. I’ve been working on a simple project and come across this road block.
I’m trying to spawn an object and move it across the screen from
X coordinate 480 —> X coordinate 0. A new object will spawn every 3 seconds and when one object moves pass X coordinate -50 then I want to remove it from the system, but I still want the others to be displayed and moved on the screen.
I don’t know how to setup the “function” to remove the object when it moves pass X coordinate -50.
I have tried a few methods, but they usually ended up removing all the objects.
One last issue with my codes. When the second object spawn, the first object stop moving and so forth. I highly appreciate any suggestions and helps anyone can provide me.
Long story short. Here are my noob codes:
[lua]-- display object and setup movement
local levelObject = function ()
local smallobject
smallobject = display.newImageRect(“smallobject.png”, 100, 51.5)
physics.addBody(smallobject, “dynamic”, {density = 1, friction =
0,bounce = 0 })
smallobject.x = 550
smallobject.y = math.random(50, 120)
levelGroup:insert(smallobject)
gameGroup:insert(levelGroup)
local function moveObject()
local speed = 1
smallobject.x = smallobject.x - speed
end
Runtime:addEventListener(“enterFrame”, moveObject)
end
– spawn object
local objectSpawner = function( event )
levelObject()
end
timer.performWithDelay(3000, objectSpawner, 10)
Runtime:addEventListener( “enterFrame”, objectSpawner )
[import]uid: 12455 topic_id: 4995 reply_id: 304995[/import]