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

Author Topic: How can I resize my view when my window size changes but...  (Read 5999 times)

0 Members and 1 Guest are viewing this topic.

sofakng

  • Newbie
  • *
  • Posts: 18
    • View Profile
How can I resize my view when my window size changes but...
« on: February 07, 2009, 04:53:19 am »
Let's say I have a window with a size of 200x200.  Let's now say I did a RenderWindow.CurrentView.Move(-100, 100) so that (0, 0) is now drawn at the center of my screen.

Now let's say I resize my window to 400x400.  I'm able to create a new view with the correct size (400x400) but I want my view to stay centered on the same spot as before.  I want everything my new view to show screen space around the center of the screen.

For some reason I just can't think this through but it seems to make sense.  If I enlarge my game window I want to see more of the game but the center of my display shouldn't change.

(NOTE: I know in most games that resizing the window doens't allow you to see more but for my game this makes sense...)

Thanks for any help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How can I resize my view when my window size changes but...
« Reply #1 on: February 07, 2009, 09:00:00 am »
Why don't you just move your new view like the old one, to center it ?

PS: please post in the correct forum, don't just put everything under "General"
Laurent Gomila - SFML developer

sofakng

  • Newbie
  • *
  • Posts: 18
    • View Profile
How can I resize my view when my window size changes but...
« Reply #2 on: February 11, 2009, 07:52:28 pm »
I'm not sure what you mean...

If I moved -100 units on the X, then -50, then -25, that would be -175 total for the X.

Are you saying to manually keep track of everytime I call Move() and then after resizing my window call it again with my totals?

It seems like storing View.Center and then re-assigning it works exactly like I'd want but I am having a strange problem.

With certain Center values and FloatRect (for the view) my sprites are drawn very jagged.  I'm still trying to diagnose what exactly values are making this happen though...

EDIT: Could it be because I'm using floating point values (eg. 270.5) for the View.Center variable?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How can I resize my view when my window size changes but...
« Reply #3 on: February 11, 2009, 08:58:37 pm »
Quote
It seems like storing View.Center and then re-assigning it works exactly like I'd want

Yeah, I confirm.

Quote
Could it be because I'm using floating point values (eg. 270.5) for the View.Center variable?

I guess you have to test to make sure. But it could be that, yes.
Laurent Gomila - SFML developer

sofakng

  • Newbie
  • *
  • Posts: 18
    • View Profile
How can I resize my view when my window size changes but...
« Reply #4 on: February 11, 2009, 11:15:09 pm »
Hmmm, I'm really at a loss here.

Here is the code for when my window resizes:

Code: [Select]

         Dim cameraX As Single = m_renderWindow.CurrentView.Center.X
         Dim cameraY As Single = m_renderWindow.CurrentView.Center.Y

         m_renderWindow.CurrentView.SetFromRect(New FloatRect(pnlRenderWindow.ClientRectangle.Left, pnlRenderWindow.ClientRectangle.Top, pnlRenderWindow.ClientRectangle.Right, pnlRenderWindow.ClientRectangle.Bottom))
         m_renderWindow.CurrentView.Center = New Vector2(cameraX, cameraY)


As you can see, I'm grabbing the CurrentView.Center and storing it, then resizing the CurrentView using SetFromRect.  (pnlRenderWindow.ClientRectangle is client size [eg. rendering area] of my Windows forms panel that I'm drawing onto).

After that, I'm setting the new CurrentView's center to what it was previously.

Here is a screenshot of what I'm referring to:

Before resizing (looks perfect):


After resizing (notice the artifacts [?] on the black lines)


Also, notice that the CurrentView.Center is set to a fractional size in both the "good" and "bad" screenshots.  The only thing that changed is the form size (displayed as Form: in the statusbar of the screenshots)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How can I resize my view when my window size changes but...
« Reply #5 on: February 12, 2009, 07:59:34 am »
What about bigger sizes?
Laurent Gomila - SFML developer

sofakng

  • Newbie
  • *
  • Posts: 18
    • View Profile
How can I resize my view when my window size changes but...
« Reply #6 on: February 12, 2009, 01:13:21 pm »
Unfortunately, yes :(

sofakng

  • Newbie
  • *
  • Posts: 18
    • View Profile
How can I resize my view when my window size changes but...
« Reply #7 on: February 16, 2009, 07:16:42 pm »
Anybody have any clues about this...? :(

 

anything