tiling a better way

This is a discussion on tiling a better way within the Game Programming forums, part of the General Programming Boards category; Is there a better way than what I have for tiling? When the tiles are drawn it is to represent ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    tiling a better way

    Is there a better way than what I have for tiling? When the tiles are drawn it is to represent a city. I have an array that stores the index of which tile to draw and than use a loop to draw them. The tiles are 11px wide with the game having a resolution of 640x480 that's 58 tiles.

    Code:
       int arr[58] = {0,1,2,0,1,2,0,1,2,0,0,1,2,0,2,0,1,0,2,0,0,0,1,0,1,0,0,2,0,3,0,0,1,2,2,0,0,1,0,0,1,0,1,0,2,0,1,0,0,2,0,0,1,1,1,1,1,0};
    
       for(i = 0; i < 58;i++)
          draw_sprite(buffer,buildings[arr[i]],i*buildings[arr[i]]->w,SCREEN_H-16-buildings[arr[i]]->h);
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I just hate it when n00bs try to create tutorials to program stuff and people learn stuff wrong.

    Use a struct or a class for your tiles. You can hold a LOT more information that way. Think about it, you can have animated tiles, blocking flags, event triggers, etc. for each tile, instead of just a static tile graphic.

    Also, try not to have your map hardcoded in. Make a map loader and think up of a format to store your maps. It isn't as hard as you think. Just look up cstdio or fstream. Heck, my first map files were just ASCII text files containing blocks of numbers for the tiles.

    Your drawing is just fine, that is how a lot of people do it, and it is efficient, until you start working with large maps. If you don't plan on using that big of maps, you'll be just fine. If you want any kind of scrolling, you'll need to learn how to offset it.

    Oh, here is an example of a struct for a tile

    Code:
    struct Tile
    {
       int Frame[3];
       bool Blocking;
    };
    That is a very simple tile struct. It gives you three frames of animation and a blocking flag. The tiles I'm using in my current project has a bunch of detail, and I have about 30 lines of code just to describe one tile. I'm going a little overboard on detail, but I plan on making it to where I can use the same tile engine on just about every project I can dream up that uses a tile engine.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I was asking for help not posting a tutorial. This isn't for a playable tilemap either. It's for generating a city for the title screen in my game.
    Last edited by lambs4; 09-07-2003 at 06:04 PM.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    You asked for a better way to do tiling and I told you how. I did "help" you. Your way is fine, but I was just telling how to do it better, like you asked for. I didn't give you a tutorial, if you asked for a tutorial I would've made up a word document providing extensive help on drawing tiles in 3D, scrolling, optimizing, and allowing tons of effects.

  5. #5
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    I just hate it when n00bs try to create tutorials to program stuff and people learn stuff wrong.
    Dude, he was commenting on the first line in your post. I think he thinks you were accusing him of making bad tutorials.

    You've both got your wires crossed!

  6. #6
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    No dude, I was saying he probably read how to do it from a n00b that didn't know what he was talking about.

    Sorry for saying that so vaguely.

  7. #7
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    Hey French, may I see an example of your tile engine?

  8. #8
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    Which one? I've done several. The one I'm working on right now isn't near being even playable yet.

  9. #9
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    Actualy I don't need to see it now, I finished mine. I just wanted to see how you did some things Working on a map editor now, and trying to make some decent tiles... You wouldnt happen to know a place to get some free tiles would you?

  10. #10
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I've always made my own, sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Faster tiling methods?
    By suzakugaiden in forum Game Programming
    Replies: 2
    Last Post: 01-06-2006, 10:46 PM
  2. OpenGl 2D Tiling problem
    By werdy666 in forum Game Programming
    Replies: 1
    Last Post: 09-29-2002, 11:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21