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

Pages: [1]
1
Hi,
I want to check if an sf::Shape contains the mouse's global bounds (and if left mouse button is clicked), and created the function below:
bool isRectClicked(sf::RectangleShape &rect, sf::RenderWindow &window) {
        sf::IntRect rect(rect.getPosition().x, rect.getPosition().y, rect.getGlobalBounds().width,  
        rect.getGlobalBounds().height);
        if (rect.contains(sf::Mouse::getPosition(window)) && (sf::Mouse::isButtonPressed(sf::Mouse::Left))) {
                return true;
        }
        return false;
}
 

However it says sf::RectangleShape has no member contains. How would I do this or do I have to do it the longer way by checking if the cursor is within the shape dimensions?

2
Graphics / Re: Check collision with vector of shapes
« on: April 07, 2016, 12:02:05 am »
Thanks for both responses, I thought the way to do it was with a for loop, I was just a bit disbelieving :P

3
Graphics / Check collision with vector of shapes
« on: April 06, 2016, 02:57:24 pm »
Hi, what I want to do is check for collision of an sf::FloatRect between any other sf::FloatRect stored in a vector. I don't know how one would do this really. I would of thought you could use a for loop but I'm not sure   :-\
std::vector<sf::FloatRect>myFloatRects(100);                     //  100 floatRects of sf::Shape
sf::FloatRect myPosition = myShape.getGlobalBounds();
if (myPosition.intersects(myFloatRects)){                               // if myPosition intersects any of myFloatRects
//do something
}
 
 

4
Graphics / Re: AW: Getting nearest sf::RectangleShape
« on: April 04, 2016, 05:18:32 pm »
I'm still not certain that I understood your problem, but for closest rect to point I've found multiple StackOverflow and similar answers. Have you searched there already?

I've probably described it badly but basically yes, I am trying to get the closest rect to a point. I did have a brief look but couldn't find any. Any links please?

5
Graphics / Re: Getting nearest sf::RectangleShape
« on: April 03, 2016, 07:39:23 pm »
Yes, but with x, y (the point from which you get the nearest rect) being a sf::RectangleShape. Also just to clear up the rectangles are stored in the vector levelGenerator.
 

6
Graphics / Getting nearest sf::RectangleShape
« on: April 03, 2016, 12:15:40 am »
Hi, I'm trying to make a function that returns the nearest sf::RectangleShape, but I can't really grasp the concept yet. If I'm right in saying you can store the minimum X and Y value required to fit in all the points of a shape in a sf::FloatRect, how can you use this to determine the closest sf::RectangleShape? Can you use the x value with the point you're measuring from's x value and so on? I came up with the following code and compiled it but it doesn't work correctly. I may have the completely wrong idea though so feel free to correct me.     
 

std::vector<myGameClass> levelGenerator(50)                               // contains the sf::RectangleShapes
...

std::vector<sf::FloatRect> floatRectVec(50);                                           //vector to store the floatRects's
std::vector<int> floatRectDistances(50);                                               //vector to store the y distance
sf::FloatRect playerGlobalBounds = player.getGlobalBounds();             // player is the point measuring from
for (int vecObjects = 0; vecObjects < levelGenerator.size(); vecObjects++){
   sf::FloatRect tmpFloatRect = levelGenerator[vecObjects].rectangleShape.getGlobalBounds();
   floatRectVec[vecObjects] = tmpFloatRect;
   floatRectDistances[vecObjects] = (tmpFloatRect.height  -  playerGlobalBounds.height);
   std::cout<<floatRectDistances[vecObjects];                           //for debugging
 
 // ...using floatRectDistances[vecObjects] get the nearest sf::RectangleShape
}
 
 


 

7
Graphics / Is it possible to hide the border of a RenderWindow?
« on: March 31, 2016, 04:00:15 am »
In a game I'm making, I want to be able to go completely full screen, with no borders (title panel, etc) and still be able to use the render window however I want. The windows tray would be fine left alone, it's just the border I'm interested in really. I know it wouldn't make that much difference, but it would be much better for my game if this was possible. Also would it be possible to do this if you created the window using openGL directly, and then modifying it from there? Any advice would be appreciated.

Pages: [1]