Results 1 to 4 of 4

Thread: [RESOLVED] 2D Terrain Without using 500 000 kB of Memory

  1. #1

    Thread Starter
    Addicted Member cc2^^'s Avatar
    Join Date
    Apr 2008
    Location
    Right behind you.
    Posts
    165

    Resolved [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

    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

    Thanks for all help given!
    I think I am, therefore, I am. I think.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Last edited by LaVolpe; Apr 23rd, 2010 at 02:28 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    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?
    W o t . S i g

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width