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

Pages: [1]
1
General / SFML 2.0 sf::Mouse::GetPosition() returning wierd coords.
« on: November 23, 2011, 09:59:30 pm »
Hello all,

I am trying to return my mouse cursor position so I can check to see if something is clicked or not.

Currently this is my code
Code: [Select]

 sf::Event currentEvent;
    while(m_GameWindow.PollEvent(currentEvent))
    {
        if(currentEvent.Type == sf::Event::MouseButtonPressed)
        {
            sf::Vector2i mouse_pos = sf::Mouse::GetPosition();
            bool clicked = TravelBoard.CheckForTilesClicked(mouse_pos);
            std::cout<<clicked<<std::endl;

        }
}


when I print my pos.x and pos.y they are much higher than they should be, for instance if I click as close to the top left of the screen as possible i get something like (1028,698) instead of something closer to (0,0).

What am i doing wrong in this instance to get a larger position than the one I should be getting?

Thanks!

2
General / SFML 2.0 sf::Rect usage.
« on: November 18, 2011, 09:13:16 pm »
Are sf::Rects attached or managed by another class like sf::Sprite or are they self managed?
For instance if sf::Rect is part of sf::Sprite, does sf::Sprite update the sf::Rect position so we can easily do the sf::Rect< T >::Intersects,
or do I have to create and manage  sf::Rect objects manually?
   
I am looking into the documentation but I am not seeing anything that directly answers this question, so I will assume I need to create and manage rect locations manually.

3
General / [SOLVED] SFML 2.0 restricitng how far sf::View can move.
« on: November 16, 2011, 10:47:43 pm »
This isn't necessarily a SFML related question, more likely I just am having a hard time wrapping my head around the logic needed to restrict the sf::View movement.

I want the view to move with the player, however I do not want it to display past a certain set of coordinates, whatever my play field will be (0,0) to (800,2000) or whatever.

Currently I use GetPosition on a player sprite and then set the center of my view to the same position.

Then I try to check the edges of the view against coords to stop it from moving, which I am doing all wrong so far.

Code: [Select]


sf::Vector2f player_pos = PlayerSprite.GetPosition();
sf:vector2f view_center = View.GetCenter();
sfVector2f view_size = View.GetSize();

if(view_center.x - (view_size.x /2) >= 0)
{
   View.SetCenter(player_pos)
}


I have also tried
Code: [Select]


if(player_pos.x - (view_size.x /2) >= 0)
{
   View.SetCenter(player_pos)
}

This appears to work if I don't go too far left, when I do the view freezes, because my equation obviously will never equal or go above 0;

I guess I am looking for some advice to stop the view from moving based on player position. I know i need some combonation of Player position, view size and position. But so far my attempts have all been thwarted.

Thanks!


 :P

4
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.

Pages: [1]