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

Author Topic: Get position of entity local to a window/view  (Read 1388 times)

0 Members and 1 Guest are viewing this topic.

Gauzr

  • Newbie
  • *
  • Posts: 20
    • View Profile
Get position of entity local to a window/view
« on: June 12, 2015, 06:48:32 pm »
Hi, I would like to get simply the y coord of a shape, but when I try do this it only gets the y distance from it's origin. I don't want this. I want to get the y coord of the whole 600x600 window (with 0, 0 at top left) but using setOrigin. Sorry if my English was a bit bad.


shape.setOrigin(-50, -400);
...


int shapepos_y = shape.getPosition().y ; // when the shape moves up 50 for example, it only returns -50, but I need it -350

std::cout<<"shapepos_y =" << shapepos_y;
 
« Last Edit: June 12, 2015, 06:51:19 pm by Gauzr »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10845
    • View Profile
    • development blog
    • Email
Re: Get position of entity local to a window/view
« Reply #1 on: June 12, 2015, 07:39:51 pm »
getPosition() provides the position of the origin.

I suggest you read the official tutorials (again), because setting the origin to negative value is very rarely what you actually want to do. To set he shape's position use setPosition().
« Last Edit: June 12, 2015, 07:53:14 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3357
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Get position of entity local to a window/view
« Reply #2 on: June 12, 2015, 07:52:30 pm »
I am curious as to what you intended to achieve with this:
shape.setOrigin(-50, -400);
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Gauzr

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Get position of entity local to a window/view
« Reply #3 on: June 12, 2015, 08:33:09 pm »
Ah, now I think I could of just setPosition(positive cords) done instead... This was the solution to this, thanks for the info.

 

anything