lua - Spawning clouds seamlessly -


i'm trying make game have clouds spawn seamlessly. map has endless x axis , used put around 1000 10000 clouds across distance, they'd stop if you'd go far left or right , amount might have caused lag on machines guessed.

one of ways thought fixing spawning them seamlessly. currently, have max amount of foreground clouds , background clouds spawn them on distance of 4000 try , 'help' seamless-ness, doesn't work.

i remove clouds if they're far away player (there's camera system they'd out view time they're removed. they're removed 3200 pixels away player), problem still can see them spawn (especially ones @ top of map)

the view port size 800x600.

here's code adds them:

    if curamountfg < maxamountfg         local cloud=cloudmod.create(player.entity.position.x+math.random(-4000,4000),math.random(0,50),math.random(1,6),"fg")         table.insert(clouds,cloud)         curamountfg=curamountfg+1     end     if curamountbg < maxamountbg         local cloud=cloudmod.create(player.entity.position.x+math.random(-4000,4000),math.random(100,3000),math.random(1,6),"bg")         table.insert(clouds,cloud)         curamountbg=curamountbg+1     end 

and here's code deals removing them(l left side of view port , w width):

    cloudindex, cloud in pairs(clouds)         if cloud.entity.position.x+cloud.entity.img:getwidth() < l-3200 or cloud.entity.position.x > (l+w)+3200             curamountfg=cloud.ground=="fg" , curamountfg-1 or curamountfg             curamountbg=cloud.ground=="bg" , curamountbg-1 or curamountbg             print(curamountfg)             table.remove(clouds,cloudindex)         end     end 


Comments