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

Author Topic: Changing the world origin in C++ SFML  (Read 154 times)

0 Members and 1 Guest are viewing this topic.

LTahboub

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Changing the world origin in C++ SFML
« on: June 28, 2020, 10:47:14 am »
Hello Everybody,

I've recently gotten into SFML and as an exercise to get more comfortable (and have fun), I started translating some Coding Challenges done by Daniel Shiffman on his Youtube channel, The Coding Train. Upon attempting to translate a star field effect in SFML, I started searching for the right function in SFML that would change the world origin from the top-left of the screen to the center. The closest thing I found to this was the setOrigin function, but that only works for sprites and not the whole window/screen. If you didn't understand my description of this function, it would be the equivalent of the translate(x, y) function in Processing. Any help would be appreciated.
« Last Edit: June 28, 2020, 10:48:49 am by LTahboub »

G.

  • Hero Member
  • *****
  • Posts: 1454
    • View Profile
Re: Changing the world origin in C++ SFML
« Reply #1 on: June 28, 2020, 06:35:51 pm »
Check the sf::View class (tutorial, doc)

Moving the view half the window size in the top left direction would put 0, 0 in the middle of the screen.

Hapax

  • Hero Member
  • *****
  • Posts: 2999
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: Changing the world origin in C++ SFML
« Reply #2 on: July 01, 2020, 05:22:24 pm »
G, I would say that it would simpler to just set the view's center to (0, 0) ;D
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

G.

  • Hero Member
  • *****
  • Posts: 1454
    • View Profile
Re: Changing the world origin in C++ SFML
« Reply #3 on: July 01, 2020, 09:04:09 pm »
True, true...  ;D