hi.
so I want to create a animation where a series of stars appearing in line with a border, showing one by one, creating a square star border. And when the last star appear to create a star square border, the first appeared will be disappeared, following the next star, and circling around the border until the whole stars disappeared.
I have tried using a few nested for’s, the appearing stars work well. here’s the problem; the disappearing function doesn’t work as what I want. it disappear, and re-appear again. here is the code.
local border = {} for i = 1, 23 do border[i] = {} end local x = 0 local y = 0 --insert stars for i = 1, 4 do x = 0 y = 0 for j = 1, 23 do if i == 1 then border[i][j] = display.newImage(fg, star, 185+x, 65) border[i][j].alpha = 0 x = x + 30 elseif i == 2 then border[i][j] = display.newImage(fg, star, 845, 65+y) border[i][j].alpha = 0 y = y + 30 elseif i == 3 then border[i][j] = display.newImage(fg, star, 845-x, 725) border[i][j].alpha = 0 x = x + 30 elseif i == 4 then border[i][j] = display.newImage(fg, star, 185, 725-y) border[i][j].alpha = 0 y = y + 30 end end end --display stars for i = 1, 4 do x = 0 for j = 1, 23 do if i == 1 then local function starAppear() transition.to(border[i][j], {delay = 10+x, time = 100, alpha = 1, onComplete = function() starAppear() end}) x = j\*10 end starAppear() elseif i == 2 then local function starAppear() transition.to(border[i][j], {delay = 230+x, time = 100, alpha = 1, onComplete = function() starAppear() end}) x = j\*10 end starAppear() elseif i == 3 then local function starAppear() transition.to(border[i][j], {delay = 460+x, time = 100, alpha = 1, onComplete = function() starAppear() end}) x = j\*10 end starAppear() elseif i == 4 then local function starAppear() transition.to(border[i][j], {delay = 690+x, time = 100, alpha = 1, onComplete = function() starAppear() end}) x = j\*10 end starAppear() end end end local function disappear() for i = 1, 4 do x = 0 for j = 1, 23 do if i == 1 then local function starDisappear() transition.to(border[i][j], {delay = 10+x, alpha = 0}) x = j\*10 end starDisappear() elseif i == 2 then local function starDisappear() transition.to(border[i][j], {delay = 10+x, alpha = 0}) x = j\*10 end starDisappear() elseif i == 3 then local function starDisappear() transition.to(border[i][j], {delay = 10+x, alpha = 0}) x = j\*10 end starDisappear() elseif i == 4 then local function starDisappear() transition.to(border[i][j], {delay = 10+x, alpha = 0}) x = j\*10 end starDisappear() end end end end timer.performWithDelay(1000, disappear)
this is a very long for, so if anybody can come up with a better for, would be really appreciated.