SFML community forums

Help => Graphics => Topic started by: deathsangel on April 29, 2009, 05:29:55 am

Title: Tile Engine
Post by: deathsangel on April 29, 2009, 05:29:55 am
Can somebody tell me how one would approach making a tile engine.
I used to use sdl so im used to being to just blit a surface.
Is this possible in sfml if so how do you do it?

example code from sdl
Code: [Select]

for (int r = 0; r < rows; r++)
{
    for (int c = 0; c < columns; c++)
    {
          SDL_Rect rect = {c * tileWidth, r * tileHeight, tileWidth, tileHeight}
         
          switch(map[r][c])
          {
                case 0:
                     break;
                case 1:
                     SDL_BlitSurface(tileImage, NULL, screen, &rect);
                      break;
          }
    }

}

So pretty much is it possible to recreate something similar in sfml.  Or if not what should I do?[/code]
Title: Tile Engine
Post by: Hiura on April 29, 2009, 01:24:25 pm
with an image manager (there is one on my wiki), and a set of sprite (eg a std::vector).

Isn't there already one tile engine on the official wiki ?
Title: Tile Engine
Post by: SamuraiCrow on April 30, 2009, 06:08:48 pm
There is this resource manager (http://www.sfml-dev.org/wiki/en/sources/resource_manager) on the official Wiki.  Also, in SFML 2.0 there is planned to be a batch-rendering mode that will improve the performace of tile maps.
Title: Tile Engine
Post by: SamuraiCrow on April 30, 2009, 06:36:34 pm
After thinking about it for a while, you could use the sf::view class to scroll around a bunch of sf::sprite objects placed at absolute coordinates.  That way you wouldn't have to calculate which tiles are visible and which tiles are not.
Title: Tile Engine
Post by: csiz on April 30, 2009, 09:39:24 pm
what is batch rendering? I couldn't find on google :(

edit:I logged in to see if anyone replied and oaa new message in this thread...and its my own message :lol:
Title: Tile Engine
Post by: SamuraiCrow on May 01, 2009, 06:51:21 pm
Batch rendering is the 2d equivalent to mesh rendering in 3d.  It means that since the vertex between 4 tile images is shared between them, it will only calculate the vertex position once and apply it to all 4 tiles.