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

Author Topic: calculating pixels in xy  (Read 1737 times)

0 Members and 1 Guest are viewing this topic.

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
calculating pixels in xy
« on: October 24, 2015, 10:17:27 pm »
Hi,
I don't know this is related to SFML or not but i want to know it.
how i must calculate to where i must put my sprite or shape? right now according to window resolution  i doing with a Approximate x-y in my mind and start program and see where is it and then i will make it accurate.
i want to know is there any formula for example that will calculate the center of window or any where of window? that i want need little help here i dont know where to start!
thanks.

Spirro

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: calculating pixels in xy
« Reply #1 on: October 25, 2015, 01:39:52 am »
If you are setting the size of your window on creation then you know it's dimensions.  The top left corner is 0,0.  The bottom right is window width, window height.  You can figure out what you need from there, but just in case you are allowing window resizing you can get the size of the current render area of the window with http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Window.php#ad2b55a731ba1680fe67292991ef1610e then calculate positions from there.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: calculating pixels in xy
« Reply #2 on: October 26, 2015, 10:07:50 pm »
One way to calculate the centre of the window and still take into account any view transformations is to just return the view's centre:
sf::Vector2f center = window.getView().getCenter();

This works with sf::RenderWindow but not sf::Window.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*