It looks like you're new here. If you want to get involved, click one of these buttons!
w=application:getContentWidth() h=application:getContentHeight() application:setBackgroundColor(0) local random=math.random local tex1 = Texture.new("mExplosion2.png") local tex2 = Texture.new("mExplosion3.png") local tex3 = Texture.new("mExplosion4.png") local tex4 = Texture.new("mExplosion5.png") local tex5 = Texture.new("mExplosion6.png") local tex6 = Texture.new("mExplosion7.png") texs = {tex1, tex2, tex3, tex4, tex5, tex6} -- for later randomization local life = 10 local fps =0 local fpsText = TextField.new(nil, math.ceil(fps) ) fpsText:setPosition(50,50) fpsText:setScale(3) fpsText:setTextColor(0xffffff) stage:addChild(fpsText) local interval = 250 --change it! local timer = Timer.new(interval) local timeMsec = 0 local timeSec = 0 local timeText = TextField.new(nil, timeSec) timeText:setPosition(150,50) timeText:setScale(3) timeText:setTextColor(0xffffff) stage:addChild(timeText) function gomad() timeMsec += interval timeSec = math.ceil(timeMsec/1000) timeText:setText(timeSec) if random(0,1) == 0 then explode1(random(w), random(h)) else explode2(random(w), random(h)) end --explode1(random(w), random(h)) --explode2(random(w), random(h)) collectgarbage("collect") --print(fps, timeSec) fpsText:setText(math.ceil(fps)) if fps < 30 then life -= 1 end if life <= 0 then timer:stop() end end function explode1(x,y) local boom=Particles.new() boom:setPosition(x,y) boom:setAlpha(0.1) stage:addChild(boom) local boom2=Particles.new() boom2:setPosition(x,y) boom2:setAlpha(0.1) stage:addChild(boom2) boom:setTexture(texs[2]) for i = 1,10 do boom:addParticles({{x=0,y=0,size=50,alpha=1,ttl=random(25,50),speedAngular=5,speedX=random()-0.5,speedY=random()-0.5,decay=1.04,decayAlpha=0.97}}) end boom2:setTexture(texs[3]) for i = 1,10 do boom2:addParticles({{x=0,y=0,size=random(25,75),alpha=1,ttl=random(25,100),speedAngular=2,speedX=random()-0.5,speedY=random()-0.5,decay=1.01,decayAlpha=0.97}}) end local boom4=Particles.new() boom4:setPosition(x,y) boom4:setAlpha(0.6) stage:addChild(boom4) boom4:addParticles({{x=0,y=0,size=1,alpha=1,speedGrowth=10,ttl=25,decay=1.05,decayAlpha=0.84}}) end function explode2(x,y) local boom=Particles.new() boom:setPosition(x,y) boom:setAlpha(0.3) stage:addChild(boom) local boom2=Particles.new() boom2:setPosition(x,y) boom2:setAlpha(0.1) stage:addChild(boom2) local boom3=Particles.new() boom3:setPosition(x,y) boom3:setAlpha(0.2) stage:addChild(boom3) local boom4=Particles.new() boom4:setPosition(x,y) boom4:setAlpha(0.5) stage:addChild(boom4) boom4:addParticles({{x=0,y=0,size=1,alpha=1,speedGrowth=10,ttl=50,decay=1.05,decayAlpha=0.91}}) boom:setTexture(texs[4]) for i = 1,15 do --for i = 1,15 do boom:addParticles({{x=0,y=0,size=50,alpha=1,ttl=random(25,50),speedAngular=0,speedX=random()-0.5,speedY=random()-0.5,decay=1.04,decayAlpha=0.97 }}) end boom2:setTexture(texs[3]) for i = 1,7 do --for i = 1,7 do boom2:addParticles({{x=0,y=0,size=150,alpha=1,ttl=random(25,100),speedAngular=0, speedGrowth=1,speedX=random()-0.5,speedY=random()-0.5,decay=1.01,decayAlpha=0.97}}) end boom3:setTexture(texs[1]) for i = 1,20 do --for i = 1,20 do boom3:addParticles({{x=0,y=0,size=random(20,50),alpha=1,ttl=random(25,50),speedAngular=5,speedX=random()-0.5,speedY=random()-0.5,decay=1.05,decayAlpha=0.98}}) end end function onEnterFrame(event) fps = 1/event.deltaTime --print(fps, timeSec) end stage:addEventListener(Event.ENTER_FRAME, onEnterFrame, self) timer:addEventListener(Event.TIMER, gomad, timer) timer:start() |
Comments
In your code you keep adding Particles sprites to stage, but you never remove them! It seems that gideros starts to lag when you reach more than 10k sprites.
You should reuse your particle sprites: create them once and for all for each texture, then just add new particles to them and let gideros remove the particles based on the ttl.
Graph shows min, current and max fps, interval is 1ms
Project attached
Likes: SinisterSoft
I really appreciate how you corrected my tentative "work". I learned several stuff by reading the new code.
The performances are just amazing and entirely stable. Now nothing will prevent me to blow things up! This is right. The worse thing is I wanted to design the code like this at first, and then, based on a stupid feeling, I changed my mind. Getting older does not help!
Thank you for your help guys. That was really appreciated.
Likes: SinisterSoft, MoKaLux, antix