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

Author Topic: Resolution independent drawing. Scaling?  (Read 6952 times)

0 Members and 1 Guest are viewing this topic.

Hooch

  • Newbie
  • *
  • Posts: 6
    • View Profile
Resolution independent drawing. Scaling?
« on: February 19, 2014, 11:33:19 pm »
Hello.
I'm new to game making.

The only game I created before was simple Snake like game in STL. But it was fixed resolutions and I was always drawing ant hard coded (x, y) coordinates.

I know the idea of heving game world units independed of screen resolution units. Like in all 3D games.

I wold like to know how to do do it properly in SFML. When user changes resolutions I have to show him the same amount of screen. (Just like scalling). I don't want to show smaller PART of screen. But the same "amount" of game world but in lower resolution.

Additionally I would like to have scrolling in game. I can't display whole world in one window.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

Hooch

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Resolution independent drawing. Scaling?
« Reply #2 on: February 21, 2014, 12:41:00 am »
http://www.sfml-dev.org/tutorials/2.1/graphics-view.php

Thanks. That is exactly what I was looking for.


One side question. When using Box2D with SFML and Views I don't have to "scale" Box2D objects?
Can I just create game world using "meters" and then use Views properties to display it properly to the screen?

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: Resolution independent drawing. Scaling?
« Reply #3 on: February 21, 2014, 06:41:12 am »
I find it's easier to think of your Box2D simulation as acting in a different coordinate system. So you might have boxes that are "1 box2d unit" wide, but then in your renderer that might correspond to boxes that are 3 "render units" wide, which is transformed by the sf::View to 40 pixels wide (say) depending on the zoom level.

But yes, you could have one coordinate system where 1 box2d unit corresponds directly to a sf::Rect of width 1, which would then be transformed by the sf::View to the screen coordinate system.

Hooch

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Resolution independent drawing. Scaling?
« Reply #4 on: February 21, 2014, 09:28:24 am »
I find it's easier to think of your Box2D simulation as acting in a different coordinate system. So you might have boxes that are "1 box2d unit" wide, but then in your renderer that might correspond to boxes that are 3 "render units" wide, which is transformed by the sf::View to 40 pixels wide (say) depending on the zoom level.

But yes, you could have one coordinate system where 1 box2d unit corresponds directly to a sf::Rect of width 1, which would then be transformed by the sf::View to the screen coordinate system.

Thanks for that.
I read to keep Box2D in range of 1 to 10 units for simulation.

I'm thinking of heving global variable (#define maybe) that will define Box2D World scale. And then in all simulations I'll use size/SCALE. I can always use scale of 1.

 

anything