• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Worms-Like Destructable terrain (Solved)

T

Theodor

Guest
I am currently trying to create a game with destructable terrain like in the worms games. I have currently been able to create one with a code that draws a black circle on the white terrain, which then is created into a sprite and replaces the old sprite, giving it a new collision mask.

My problem is that this constantly eats more and more ram each time the function is called, untill the game crashes. I use the "sprite_create_from_surface" function and have located that this is the reson for the constant ram loss.

My question, does anyone know how this memory problem can be prevented or any other way to create a destructable terrain?
 
R

renex

Guest
  1. Have both a surface and a ds grid of appropriate block sizes.
  2. Then, when the terrain is hit, erase bits of the surface using blend modes and at the same time erase a disc from the grid.
  3. Then, use the grid for your collisions.
This is very tricky to get running, but once you do it actually runs really fast. Check this out, the game has a 8192x1024 terrain with block size 8 and is running at 60 fps on a refurbished xp office machine turned arcade:

Screenshot_9.png

In your current implementation, though, make sure you are deleting the old sprite before making a new one.
 
T

Theodor

Guest
DS Grid is something compleatly new to me, will have to look it up more.
deleting the current sprite? as in...
Are you kidding me, all I had to do was adding a "sprite_delete(spr_terrain_base);" before the "sprite_create_from_surface();" and the memory loss vanished...

Thank you sir, you are a lifesaver.

ps Will still take a look at the DS Grid thingy
 
Top