Hi, I have created several objects in a loop. I am trying to move the objects but only one object is moving. I know I need to move them through the table i placed them in but iam kind of stuck. I have stripped down the code would somebody cast a quick eye on it please?
I am missing something simple.
[lua]
local function createFollower(layer)
local layer = layer or display.currentStage
for i = 1, 10 do
local follower = display.newCircle(0, 0, 5)
follower.x = math.random(0, 320) --display.contentWidth * 0.5
follower.y = math.random(0, 480) --display.contentHeight * 0.5
follower.name = “follower”
physics.addBody(follower, { isSensor = true, radius = 20 })
follower:addEventListener(“collision”, follower)
followers[#followers + 1] = follower
function moveFollowers()
local playerTravel
local multiplier
local playerTravel = player.x
local multiplier = -1
if player.x <= 450 then scrollSpeedX = 0
else
scrollSpeedX = (playerTravel / 600) * multiplier
end
if followers[#followers].x
then
followers[#followers].x =
followers[#followers].x + scrollSpeedX
end
if player.x <= 50 then playerTravel = 480 - player.x
multiplier = 1
scrollSpeedX = (playerTravel / 300) * multiplier
end
if followers[#followers].x
then
followers[#followers].x =
followers[#followers].x + scrollSpeedX
end
end
Runtime:addEventListener(“enterFrame”,moveFollowers)
end
[/lua]
