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 - sec_goat

Pages: 1 [2]
16
Graphics / Help with logic behind displaying game map?
« on: November 11, 2011, 06:38:53 pm »
I am very new to using the SFML library, and C++ in general. However I am trying to wrap my head around some SFML best practices in loading images and displaying sprites.

I have a txt file that contains what I want my level(s) to look like. I currently read in the lines and will iterate through each character to display tiles for my map.

My question is how would I go about loading and keeping track of my images and sprites in regards to SFML best practices?

what I am thinking is just creating an image and sprite for each tile type and then rendering it based on my map.

My other problem is actually drawing the tiles to the screen, right now I am looping though my map character by character to display each tile, it does this once each frame, which is not ideal as it lags everything out. How can I display my map and only redraw tiles that need to be redrawn? I.E a mob or player moves, only drawing the floor once etc?

Code: [Select]
Class Map
{
Public:
std::Vector<std::string> ReadMap()
{
 std::string line;
       std::vector<std::string> vec;
       std::ifstream myfile("lvl/lvl1.txt");

        if(myfile.is_open()){
            while(getline(myfile, line)){ //this will keep the loop goign and grab a new line each iteration
                 vec.push_back(line);
            }

            myfile.close();
        }
        else{
            std::cout << "Unable to open File!\n";
        }
        for(unsigned int i = 0; i < vec.size(); i++){ //iterate through vecotor and display line by line to make sure map is reading right
                    std::cout<<vec[i]<<std::endl;
                 }
    return vec;
}


void DisplayMap()
{
int x,y;
    for(unsigned int i = 0; i < levelMap.size(); i++){
        for(unsigned int j = 0; j < levelMap[i].size() + 1; j++){
        std::cout<<levelMap[i][j];
        y = i * 32;
        x = j * 32;
        window.Draw(floorSprite); //Draw floors on every space first
        if (levelMap[i][j] == '#'){
            window.Draw(wallSprite);
            }
        }
        }
}

private:
sf::Image floor;
sf::Image wall;

sf::Sprite Floor;
sf::Sprite Wall;

}

Thank you all for your input.

17
General / I just wanted to say thank you.
« on: November 10, 2011, 08:29:50 pm »
This is an amazing tutorial that introduces the nuances of SFML as well as some really good (IMO) programming practices that I  have been trying to figure out for quite a while.

I am really learning a lot form this and have been looking for something like this for a long time. Can't wait for the next installments of this tutorial.

Pages: 1 [2]
anything