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

Pages: 1 ... 3 4 [5]
61
Hello,

So I have a way to click a startTile and a goalTile based off where you click and pressing LShift or LCtrl.

I used Num1 (view.zoom(1.1)) and Num2 (view.zoom(1.1)) to zoom in and out of the 250x250 (64x64) map.
        const auto mousePos = sf::Mouse::getPosition();
        const auto pixelToCoordPos = m_pGame->getWindow().mapPixelToCoords(mousePos,view);
        const sf::Vector2f tilePosFromMouse = {pixelToCoordPos.x / 64,pixelToCoordPos.y/64};
 

When I click somewhere, the tiles are off. But when I maximize the window, it all of sudden goes to the right tile. But when I zoom out it is off a few tiles on the Y-axis (undershoots it).

        if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
                        if (currentNode != nullptr) {
                                auto currTile = m_map->getTile(tilePosFromMouse.x, tilePosFromMouse.y);
                                currentNode = currTile;
                                m_map->setStartNode(currTile);
                        }
                }

Tile* Map::getTile(int columnIndex, int rowIndex)
{
        if (tileIsValid(columnIndex, rowIndex)) {
                return &m_grid[columnIndex][rowIndex];
        }
        else {
                return nullptr;
        }
}

Any idea how I can correct this? Hope I explained the situation correctly.

Thanks!


62
Graphics / Re: mapPixelToCoords and mapCoordsToPixels
« on: August 09, 2019, 11:58:11 pm »
Thank you so much, Laurent, for the clear answer. This makes total sense!

Much appreciated, have a great weekend.

63
Graphics / mapPixelToCoords and mapCoordsToPixels
« on: August 09, 2019, 07:15:32 am »
Hello,

So I know you can use MapPixelToCoords to get the target coordinates to world coordinates using an optional view. Is it similar to sf::Mouse::getPosition(window), except relative to a view?

When would you need to perhaps use MapCoordsToPixels (an example?). Obviously, it does the opposite, but why would you ever need that?

I'm just trying to understand this more because I've always used MapPixelToCoords to get my mouse position correctly, but it seems getPosition(window) does the exact same thing. Which then made me think more about it.

Much appreciated.

64
General / Re: Question about Rect
« on: August 07, 2019, 07:02:57 am »
Apology! I forgot I asked about this. I just found this bookmark. Thanks for the help, that is exactly what I needed to hear.

Cheers!

65
General / Question about Rect
« on: July 30, 2019, 07:38:11 am »
Hello,

I am currently reading a book called SFML Game Development. (pg. 76) (talks about view bounds)

When they talk about initializing the world, of course, as a rectangle upper-left lies at (0, 0). How come getting the top + height gets you the bottom right corner and height doesn't just return it? If I 'cout' the height, it is the dimension of the image, so I'm lost.

I came across this and I thought about collision detection, where you add left+width or top+height during bounds checking. Can anyone explain this further, I'd like to understand it better?

Thanks!


Pages: 1 ... 3 4 [5]