Hey guys got a small problem with an object that im creating, as the title says it, i cant move it.
This is my code:
[lua]local obstacle = {}
function Obstacles()
local numObstacles = 30
for i=1,numObstacles,1 do
obstacle = display.newImage(displayGroupBad, “Assets/obstacle.png”, true)
obstacle.x = math.random(100,300)
obstacle.y = math.random(100,620)
obstacle.speed = math.random(4,8)
obstacle.initY = obstacle.y
physics.addBody(obstacle, “static”, {density=0.1, bounce=0.1, friction=.2, radius = 12})
end
end
Obstacles()
function moveObstacles()
if obstacle.x < -50 then
obstacle.x = 500
obstacle.y = math.random(100,320)
obstacle.speed = math.random(2,6)
else
obstacle.x = obstacle.x - obstacle.speed
print(“obstacles should move”)
end
end
moveObstacles()[/lua]
Im not sure what im doing wrong, i did figure out that the moveObstacle function only gets called once, how can i make sure it gets called every update frame?