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.


Messages - ProttisSFML

Pages: [1]
1
General / Re: sf::Texture to sf::RectangleShape
« on: December 07, 2012, 03:07:15 pm »
Thanks for the heads up there, yeah there is more to the code than this but Im currently working on the resource manager aswell I just wanted to make sure that this worked.

And i have quite alot done allready, but I will definatly look into the VertexArray. The map will not move either so its a static tilemap which only shows that one picture. I just made it like this so I can have more levels as I go.

2
General / sf::Texture to sf::RectangleShape
« on: December 07, 2012, 02:53:56 pm »
Hi, im new to the forums:)

Im working on a tower defence and as of now im writing the tiled map code, this takes a map.txt with numbers in it and draw the map from that.

What im having troubles with is how i can use textures together with shapes!

Here is the current code for that:
void DrawMap(sf::RenderWindow &Window)
{
        sf::RectangleShape rect;
        rect.setSize(sf::Vector2f(BLOCKSIZE,BLOCKSIZE));
        sf::Texture rectTexture;
        for(int i = 0; i < mapSizeX; i++)
        {
                for(int j = 0; j < mapSizeY; j++)
                {
                        if(mapFile[i][j] == 0) //if the value of the map is 0 then we draw this
                                rectTexture.loadFromFile("Dirt.png");
                                        //set texture of the rectangle 0
                        else if(mapFile[i][j] == 1)//if the value of the map is 1 then we draw this
                                rectTexture.loadFromFile("Grass.png");//set texture of the rectangle 1
                //we can add more statements if we want more nunmbers for our map
               
               
                        rect.setPosition(i * BLOCKSIZE, j * BLOCKSIZE);
                        rect.setTexture(rectTexture); // Im getting an error here, cant convert
//from sf:: texture to sf::const texture
                        Window.draw(rect);

                }
        }
}

So do i need to change it to sprites maybe cant rectangular shapes have a texture only a color? Because I used sf::Color and that worked fine

Pages: [1]