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

Pages: [1]
1
General / Re: How to detect collision when RenderWindow has an sf::View?
« on: August 13, 2020, 03:55:16 pm »
That doesn't make much sense: you're trying to convert a rectangle in scene coordinates to scene coordinates (the fact that you have to cast your vector types is a good hint that something's wrong -- Vector2i defines pixels) ;)

I assume that "point" is mouse coordinates, as given by sf::Mouse::getPosition. I also assume that rect is the absolute bounding rect of an entity, as given by getGlobalBounds(). I also assume that the view that you mentioned is active in "window" when you call this function. (I wish I hadn't to assume so much stuff ;))

Then it's simple: you just have to convert mouse coordinates to "scene" coordinates, that is, coordinates in the current window's view.

bool pointRect(const sf::Vector2i& point, sf::RectangleShape& rect, const sf::RenderWindow& window) {
    return rect.getGlobalBounds().contains(window.mapPixelToCoords(point));
}

All your assumptions are correct, and I see the problem in converting the rectangle. Thanks again! This is very helpful.

2
General / Re: How to detect collision when RenderWindow has an sf::View?
« on: August 13, 2020, 03:30:02 pm »
You most likely need this function: https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1RenderTarget.php#a2d3e9d7c4a1f5ea7e52b06f53e3011f9

Thank you, but it's still not working. Here's what I have to detect whether the mouse is within a rectangle that's affected by an sf::View:

bool pointRect(const sf::Vector2i& point, sf::RectangleShape& rect, const sf::RenderWindow& window) {
    auto pos = window.mapPixelToCoords(point);
    auto topleft = window.mapPixelToCoords((sf::Vector2i)rect.getPosition());
    auto bottomright = window.mapPixelToCoords(sf::Vector2i(rect.getPosition() + rect.getSize()));
   
    return pos.x > topleft.x && pos.x < bottomright.x && pos.y > topleft.y && pos.y < bottomright.y;
}
 

Helping me figure out what I've missed would be great!

3
General / How to detect collision when RenderWindow has an sf::View?
« on: August 12, 2020, 10:16:06 pm »
Hello. I'm working on a game that uses sf::View to let the user pan and scroll around the map. However, despite lots of work, I can't find a way to have any type of collision detection (either FloatRect methods or simple math) work with sf::View.

Let's say I start with a rectangle in the center of the window, and pan such that it's now at the bottom right corner. Using .getGlobalBounds().intersects... doesn't register anything when I click the rectangle in the bottom right — only when I click where the rectangle started. Using math (mouse.x > rect.getPosition().x) doesn't work either; I don't think any aspect of a RectangleShape changes when it moves on the window due to an sf::View.

So, is there any way for me to factor a View into the calculations when I want to do collision detection?

(Any help would be appreciated!)

4
General / Re: How to port from Mac to Windows
« on: June 27, 2020, 09:49:40 pm »
By macOS specific APIs, what do you mean? I'm just using the 5 base packages — system, window, audio, graphics, and network. As for resource path handling, is using
resourcePath() + "filename"
sufficient?

5
General / How to port from Mac to Windows
« on: June 27, 2020, 07:00:00 pm »
Hello. I've been using my Mac to create an SFML project in XCode, and now my friend — on Windows — wants to take a look at it. I've searched Google and the SFML forums only to find questions asking how to port to Mac, so any advice or help would be very appreciated. Thanks!

Pages: [1]
anything