Hello.
I have a little problem. I hope you can help me to solve this one.
I have a loop that creates 4 balls
balls = {} for s = 1, 4 do balls[s] = display.newImage("recamara/rPelota.png", 50 + (s\*150), 10) group:insert ( balls[s] ) balls[s]:scale (.5, .5) balls[s].isVisible = false --physics.addBody( balls[s], "dynamic", { density=0.9, friction=0.1, bounce=.6, radius=24 } ) end
As you can see I did not addBody, because I want to add body later in the game.
now I have a function that adds the body and make the balls visible
local function four () balls[s].isVisible = true physics.addBody( balls[s], "dynamic", { density=3.0, friction=0.5, bounce=1, radius=20 } ) transition.to(tx4, {time=7000, alpha=0}) end
When I tap on the number 4, I call the function four and I supposed to see the balls falling
tx4 = display.newText ("4", 0, 0, "Helvetica", 150 ) group:insert ( tx4 ) tx4.x = 750; tx4.y = 300 tx4:setTextColor(0, 0, 0) tx4.isVisible = false tx4:addEventListener ("tap", four)
But when I call the function on --tx4 I get a “nil” value
and I put local balls on top.
So how do I create the objects with a loop
and make them not visible and no physics
and then after in another function, make them visible
and add body.?
How would I solve this problem?
Please I need help
thanks