SFML community forums

Help => Graphics => Topic started by: Qluxzz on April 03, 2013, 07:55:58 pm

Title: Scrolling tile map sfml2.0
Post by: Qluxzz on April 03, 2013, 07:55:58 pm
Hi there, I need some help with scrolling a tile map.

This is the code I got at the moment for drawing the tile map
for (int x = 0; x < worldMap.size(); x++) {
                        for (int y = 0; y < worldMap[x].size(); y++) {
                int tileId = worldMap[y][x];
               // Get the width and height of the image
                int width = 64;
                int height = 64;
                // Adjust the offset by using the width and height of the image used      
                                caveTiles[tileId].setPosition(x * width, y * height);
                // Draw the tiles
                window.draw(caveTiles[tileId]);
            }
        }

I have tried looking for others that might have done it but i can't find a good tutorial about it in sfml 2.0.
No now I'm turning to you.

Thanks in advance :)
Title: Re: Scrolling tile map sfml2.0
Post by: Haze on April 03, 2013, 08:09:10 pm
I would suggest using sf::View, very handy for this kind of feature.
There's a really good tutorial about it on the SFML wiki:
https://github.com/SFML/SFML/wiki/Tutorial%3A-Using-View
Title: Re: Scrolling tile map sfml2.0
Post by: Haze on April 05, 2013, 09:41:54 pm
You know anything about tile map collision detection? :P
I suggest you read about tile-based engines, there's plenty of tutorials.
This one is a good introduction:
http://www.gamedev.net/page/resources/_/technical/game-programming/the-guide-to-implementing-2d-platformers-r2936

I also like this one, very detailed with interactive demos, but it's aimed for Flash developer (the theory remains the same however)
http://www.tonypa.pri.ee/tbw/start.html