I have a table of about 30 small images and I am trying to have them all randomly move around the screen but only the first image is moving around, the rest show up on the screen but don’t move anywhere. My code is below. The print statement on line 3 shows me that it is correctly cycling through all the for loops so that makes me think that I’m not doing something correctly with the translate function. Any help would be greatly appreciated.
[code]
local function animate(event)
for i=1,numImages do
print(i)
xrand[i] = math.random(-100,20)
yrand[i] = math.random(-100,20)
local tDelta = event.time - tPrevious
tPrevious = event.time
xpos[i] = xpos[i] + ( 0.124*xdirection[i]*tDelta );
ypos[i] = ypos[i] + ( 0.086*ydirection[i]*tDelta );
if (xpos[i] > display.contentWidth - 5 or xpos[i] < 5 or xrand[i] > 0) then
xdirection[i] = xdirection[i] * -1;
end
if (ypos[i] > display.contentHeight - 5 or ypos[i] < 5 or yrand[i] > 0) then
ydirection[i] = ydirection[i] * -1;
end
image[i]:translate( xpos[i] - image[i].x, ypos[i] - image[i].y)
end
end
Runtime:addEventListener( “enterFrame”, animate );
[/code] [import]uid: 33154 topic_id: 14961 reply_id: 314961[/import]
[import]uid: 3826 topic_id: 14961 reply_id: 55247[/import]