SFML community forums
Help => Graphics => Topic started 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
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]
-
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 ?
-
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.
-
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.
-
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:
-
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.