Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How can you actually convert coordinates for a sf::View in the latest snapshot?  (Read 2473 times)

0 Members and 1 Guest are viewing this topic.

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
I've built SFML myself using the latest snapshot, everything works fine, however I noticed that there's no longer a convertCoords option, and instead there are some mapCoordinatesToPixels method and another one, every source tells me to use convertcoords which no longer exists, the tutorials should really be updated but what I'm really here for is to find out how to actually convert coords in the latest snapshot?

All I want is to render a camera and a sprite, and I don't want the sprite to move with the camera. Here's my code:

#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow winMain(sf::VideoMode(500, 500, 32), "Title");
        sf::View camera = winMain.getDefaultView();
        sf::Event mainEvent;

        sf::Texture logo_tex;
        logo_tex.loadFromFile("textlogo.png");
        sf::Sprite logo_spr(logo_tex);
        logo_spr.setPosition(350, 350);

        winMain.setView(camera);

        while(winMain.isOpen())
        {
                winMain.mapPixelToCoords(logo_spr.getPosition());

                while(winMain.pollEvent(mainEvent))
                {
                        if(mainEvent.type == sf::Event::Closed)
                                winMain.close();

                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) camera.move(1, 0);
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) camera.move(-1, 0);
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) camera.move(0, -1);
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) camera.move(0, 1);
                }

                winMain.clear();
                winMain.draw(logo_spr);
                winMain.display();
        }
}

However I'm getting an error when trying to convert the coords, it tells me the paramater is vector2f and not vector2i.

Any ideas?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
What you want is the other one (since you want to map sprite coords to window pixels -- mapCoordsToPixel). But why don't you use a second view instead? Call window.setView(wndow.getDefaultView()) before drawing your sprite.

And... there's no tutorial, so I don't know what you want me to update ;)
Laurent Gomila - SFML developer

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
What you want is the other one (since you want to map sprite coords to window pixels -- mapCoordsToPixel). But why don't you use a second view instead? Call window.setView(wndow.getDefaultView()) before drawing your sprite.

And... there's no tutorial, so I don't know what you want me to update ;)

Initially I was referring to the 1.6 tutorial, but the ones on the internet also tell to use convertCoords, not to mention there's a convertCoords in the 2.0 documentation that also gives a very small brief, I was pretty confused, having used that thing before. I'll try the other one though and tell you if that works.

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
It works, no conversion, nothing, all I had to do was call window.setView(camera);

Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
not to mention there's a convertCoords in the 2.0 documentation that also gives a very small brief
The online documentation matches the online release, which is the RC and which has the convertCoords function. If you compiled another version of SFML you must compile the doc that goes with it, if you want a perfect match.
Laurent Gomila - SFML developer

 

anything