[RESOLVED] 2D Terrain Without using 500 000 kB of Memory
I am currently working on a simple 2D Tile-Based game where you control a circle (you) trying to shoot down other CPU circles with a different team.
Screenshot
http://img7.imageshack.us/img7/7186/...mappsbildc.png
The Lines are "Bullets".
As you can see, the Tiles are 16x16. No problems here.
But i thought of making an option for the user to have a 1x1 Terrain,
Just like in Worms-Based-Games. You can then import a custom made picture of your own map to the game, and the game will remove all black pixels and replace them with empty space.
The problems with 1x1 Terrains is:
It eats more than 500 000 kB of Memory. I use the following code to define all Tiles:
Code:
Dim Tile(-1 To 11549, -1 To 11549) As Long
It is also very slow to draw every pixel that fits in the screen.
Or maybe you don't need a tile system to work with terrains?
Someone please point me in the right direction :confused:
Thanks for all help given!
Re: 2D Terrain Without using 500 000 kB of Memory
An array of that size and data type will take up that much memory... but so would the non-tile alternative of a picture file of 11550*11550 pixels (roughly 10 monitors wide and high).
If memory is a concern, either make the map much smaller, or use tiles of a "decent" size. If you want people to be able to make maps, create a tile based map editor (possibly allowing them to create their own tiles too).
Re: 2D Terrain Without using 500 000 kB of Memory
I'm not sure why you couldn't use tiles anyway. Let's say your tiles were 16x16 and a user gave you a 100x100 image to use. Well, 16 doesn't divide into 100 evenly, but it does divide in to 112 evenly... Draw their image over a 112x112 default background, split that new image into 16x16 tiles and use those new tiles. Just an idea.
Re: 2D Terrain Without using 500 000 kB of Memory
Just to add...
I imagine games such as Worms don't use 1x1 tiles, rather they use a monochrome 1bpp (bits per pixel) mask. If an arbitrary bit of landscape is destroyed nothing happens to the tiles (which could be quite big) instead a hole is cut in the mask. Using a monochrome mask gives you 8 pixels for every byte, that's 32 times smaller in memory than using a 32bit Long for each pixel.
There are many raster operations that can be used to render graphics. Normally if a graphic and mask are matched then it can be rendered in two phases (AND & OR). If the graphic and mask are not matched (i.e. the bits of the graphic not to be rendered are not black) then you need to pre-render the graphics to a buffer, apply an inverted mask (to make the bits not to be rendered black), then do the usual AND OR rendering to the screen buffer.
make any sense?