Hi guys,
I would very much appreciate your help.
Why below created rectangles do not “jump”?
They are created onscreen but they do not jump (print(“jumped”) is never executed in terminal window).
I get no errors and physics is started of course.
elements = display.newGroup()
elements.anchorChildren = true
elements.anchorX = 0
elements.anchorY = 1
elements.x = 0
elements.y = 0
–stage:insert(elements)
function createRectangles()
rectangle = display.newRect( 0, 0, 50, 50 )
rectangle:setFillColor(67, 255, 8)
rectangle.x = math.random(100, 200)
rectangle.y = math.random(100, 200)
rectangle.canJump = 1
physics.addBody(rectangle, “dynamic”, {density=1, bounce=0.1, friction=.2})
elements:insert(rectangle)
end
function touchAction()
for a = 1, elements.numChildren,-1 do
–if ( rectangle[a].canJump > 0) then
rectangle[a]:setLinearVelocity(0, -300)
print(“jumped”)
end
–end
end
creating = timer.performWithDelay ( 2000, createRectangles , -1 )
jumping = timer.performWithDelay ( 6000, touchAction , -1 )
Many thanks for your help.
Ivan

