Jump to content
  • Advertisement
Sign in to follow this  
Toadhead

2D game with resizing window

This topic is 2539 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all,

I'm writing a small game using SFML. At the moment all I have is a screen with a background, and some clickable buttons on it.
The buttons work fine, until I start resizing the window. For some reason the button's images are stretching out with the window, which is actualy what I want, but the mechanics stay behind. I have to click above or in front of the button before it is actually being clicked. The sprite.GetHeight() and GetPosition() functions no longer seem to work, as they still return the old parameters.

The code is actually quite big already so I find it hard to post it here, so I was just hoping for some general tips. How are these things normaly done? Is it wise to hard code the button's positions or is there another option?

I was also thinking about using a virtual screen, but I'm not sure how to do this in SFML (what kind of class to use for the drawing, and how to present this eventually to the RenderWindow. But even if using a virtual screen, would I just choose some random numbers for the screen's width and height or what's the most standard way?

Kind regards,
Rob

Share this post


Link to post
Share on other sites
Advertisement
Update: It seems I could fix my problem by using the SFML function ConvertCoordinates() which converts the mouse coordinates of the screen to the "worldview".
It seems that when a SFML window is resized, the window is resized but the View is the same. The View is like a 2D camera. Instead of using the mouse coordinates relative to the screen I have to use them relative to the View.

But I'd still like to hear how others manage these things :)

Share this post


Link to post
Share on other sites

Update: It seems I could fix my problem by using the SFML function ConvertCoordinates() which converts the mouse coordinates of the screen to the "worldview".
It seems that when a SFML window is resized, the window is resized but the View is the same. The View is like a 2D camera. Instead of using the mouse coordinates relative to the screen I have to use them relative to the View.

But I'd still like to hear how others manage these things smile.png


Actually, that is pretty much how you handle it for any 2D graphics. Or at least, in all of my experience. YMMV

Share this post


Link to post
Share on other sites
Hm maybe I just need to get used to these Views. But I tought the standard was like drawing everything to some virtual screen, than before showing the actual screen clear it and paste the virtual screen on top of it in the right size. Perhaps these SFML Views are actually the same, but since it's happening all automaticly it feels like I'm not in control and I'm going to make some mistake sooner or later like graphics that is being scaled and graphics that isn't. I guess I should do some more research about it to make sure I understand everything. But than again, I'm not going to use SFML forever so I was just wondering how people manage these things in other libraries like Allegro or SDL.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!