Hello i have this code:
It basicly make this:
these 2 rng flames on those torches
local function background() local y=math.random(850,870) local x=math.random(60,90) local p=math.random(30,50) local r=math.random(80,160) local y1=math.random(850,870) local x1=math.random(60,90) local p1=math.random(30,50) local r1=math.random(80,160) local s=-1 local function backgroundanim() local rect = display.newRect(x,y,p,p) rect:setFillColor( math.random(80, 100)/100, math.random(10, 40)/100, math.random(0, 0)/100 ) local rect1 = display.newRect(x1+560,y1,p1,p1) rect1:setFillColor( math.random(80, 100)/100, math.random(10, 40)/100, math.random(0, 0)/100 ) groupmenu:insert(1,rect) groupmenu:insert(1,rect1) transition.to( rect, { time=4000, rotation=r}) transition.to( rect, { time=5000, xScale=s, yScale=s}) transition.to( rect, { time=1000, delay=4000, alpha=1}) transition.to( rect, { time=5000, y=y-600}) transition.to( rect1, { time=4000, rotation=r}) transition.to( rect1, { time=5000, xScale=s, yScale=s}) transition.to( rect1, { time=1000, delay=4000, alpha=1}) transition.to( rect1, { time=5000, y=y-600}) timer.performWithDelay(2500,function() display.remove(rect) end) timer.performWithDelay(2500,function() display.remove(rect1) end) y=math.random(850,870) x=math.random(60,90) p=math.random(30,50) r=math.random(120,1660) y1=math.random(850,870) x1=math.random(60,90) p1=math.random(30,50) r1=math.random(120,1660) end backgroundanim() end
Then i call this whole function by using
timer.performWithDelay( 70, background, 0)
so there is many rectangles making “flame” infinite time. this function and timer are in my menu() funcion with torches and butons, i call it at the botom of my main.lua file with simply menu(). now what i’m trying to do is to distable this function when i tap the options button, i’ve achieved this by adding at the top of my menu() function :
local flamefunction=true
then at options “touch” event adding:
local function taponoptions( event ) if (event.phase == "began") then flamefunction=false ( rest of the code deleting menu buttons) end
and then i added this to function with flames.
if (flamefunction == false) then display.remove(rect) display.remove(rect1) end
But when i use my back button in options which is deleting options buttons and making my menu() again, there is 2x (twice) as meny flame rectangles and when i keep doing it they multiply always by 2… i don’t know how to stop timer.performWithDelay() or to distable this flames function when i press options button and resume it when i use return button
but without timer.perfomWithDelay() i dont know how can i do it. thou i can’t use
while ( var ==true ) do background() end
Becouse there is no delay betwen spawning rectangles so it crashes.
Can’t either spawn many rectanles or check if flamefunction is false or true.
I dont know what to do.
maybe anyone who understood this whole post will help me! sorry for my english by the way!