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

Author Topic: (Solved) Drawing sprite relative to Window positions (Beginner)  (Read 2405 times)

0 Members and 1 Guest are viewing this topic.

bobtran12

  • Guest
(Solved) Drawing sprite relative to Window positions (Beginner)
« 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.
« Last Edit: December 19, 2014, 11:01:28 am by bobtran12 »

G.

  • Hero Member
  • *****
  • Posts: 1590
    • View Profile
Re: Drawing sprite relative to Window positions (Beginner)
« Reply #1 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.
« Last Edit: December 19, 2014, 05:55:55 am by G. »

bobtran12

  • Guest
Re: Drawing sprite relative to Window positions (Beginner)
« Reply #2 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!
« Last Edit: December 19, 2014, 06:42:02 am by bobtran12 »

 

anything