Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Digot

Pages: [1]
1
General / Problems rendering TileMaps
« on: August 01, 2014, 08:23:12 pm »
Hello!

I have a Tilemap that is 5 by 5 big and has 64 by 64 big Tiles!

I'm using .tmx maps with tmxparser lib and i have only 2 FPS.

Also at when the map ends there are still buggy grass tiles. What's the problem there? . Btw that's the only thing I'm rendering right now.

Image: http://imgur.com/NoIUBbi (2 is the FPS counted by Fraps)

void DrawMap(){
        IntRect cropRect;
        for (int i = 0; i < testmap->map.layerCollection.size(); ++i)
        {
                tmxparser::TmxLayer layer = testmap->map.layerCollection[i];
                int currTile = 0;
                for (int y = 0; y < layer.width; y++)
                {
                        for (int x = 0; x < layer.height; x++)
                        {
                                if (layer.tiles[currTile].gid > 0){
                                        tmxparser::TmxTileset currTileset = testmap->map.tilesetCollection[layer.tiles[currTile].tilesetIndex];

                                       
                                        int tileIndex = layer.tiles[currTile].gid - currTileset.firstgid;
                                        cropRect.left = (tileIndex % (currTileset.image.width / 64)) * 64;
                                        cropRect.top = (tileIndex / (currTileset.image.width / 64)) * 64;
                                        cropRect.width = currTileset.tileWidth;
                                        cropRect.height = currTileset.tileHeight;

               
                                        VertexArray v(sf::Quads,4);
                                        v[0].position = Vector2f(x * 64, y * 64);
                                        v[1].position = Vector2f((x + 64) * 64, y * 64);
                                        v[2].position = Vector2f((x + 64) * 64, (y + 64) * 64);
                                        v[3].position = Vector2f(x * 64, (y + 64) * 64);

                                        v[0].texCoords = Vector2f(cropRect.left * 64, cropRect.top * 64);
                                        v[1].texCoords = Vector2f((64 + cropRect.left) * 64, cropRect.top * 64);
                                        v[2].texCoords = Vector2f((64 + cropRect.left) * 64, (64 + cropRect.top) * 64);
                                        v[3].texCoords = Vector2f(cropRect.left * 64, (64 + cropRect.top) * 64);

                                        window->draw(v, &currTileset.image.texture);
                                       
                                }
                                currTile++;
                                printf("Tile %i \n", currTile);
                        }

                }
                currTile = 0;
        }
}

Please help :)


Pages: [1]