SFML community forums

Help => Graphics => Topic started by: bobtran12 on December 19, 2014, 02:41:56 am

Title: (Solved) Drawing sprite relative to Window positions (Beginner)
Post by: bobtran12 on December 19, 2014, 02:41:56 am
If I wanted to draw a sprite at positions (28, 500) relative to the Window (for example), how would I do it?

I can't seem to use the mapPixeltoCoords properly.

I have this at the top of main():
sf::Texture tTexture;
sf::Sprite textbox;
if(!tTexture.loadFromFile("images/TextBox.png"))
                std::cout << "Error: Game failed to load 'textbox' image." << std::endl;
textbox.setTexture(tTexture);

What should I have within "while(Window.pollEvent(Event))" to make it draw at (28, 500) regardless of the current view?

Sorry, but I'm a beginner at this stuff lol.

Also, I'm on SFML 2.1.
Title: Re: Drawing sprite relative to Window positions (Beginner)
Post by: G. on December 19, 2014, 05:52:59 am
Using mapPixelToCoords with (28, 500) and a view will give you the position you have to use when drawing your sprite on this view so that it's at 28, 500 relative to the window corner.

Alternatively (and probably better) if you want to draw a sprite not relative to your views, use another view that doesn't move (or rotate or scale) so that you can simply position your sprite at 28, 500.
Title: Re: Drawing sprite relative to Window positions (Beginner)
Post by: bobtran12 on December 19, 2014, 06:04:38 am
Alternatively (and probably better) if you want to draw a sprite not relative to your views, use another view that doesn't move (or rotate or scale) so that you can simply position your sprite at 28, 500.
How do I draw the sprite using another view?

Edit: Never mind lol. I got it. Thanks!