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

Author Topic: Position of SubRect of a Sprite...  (Read 4243 times)

0 Members and 1 Guest are viewing this topic.

Ako

  • Newbie
  • *
  • Posts: 14
    • View Profile
Position of SubRect of a Sprite...
« on: June 19, 2008, 10:38:44 am »
Hey!

When I change the position of a sprite, the position of the subrect of it will not be changed, right?
Thats too bad because I want to check if the cursor is above the sprite with mySprite->GetSubRect().Contains(mousePosX, mousePosY)...

But the subrect-position is always 0, 0, ....
So I have to change the subrect whenever I change the sprite position?

Thanks!
Greets

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Position of SubRect of a Sprite...
« Reply #1 on: June 19, 2008, 11:46:37 am »
Subrect is a local rectangle, to do picking tests you must first put it in view space (ie apply any translation / rotation / scaling).

also, don't forget to convert your mouse position to view space too (it's in window space, which might not be the same if you're using a custom view or have resized your window).
Laurent Gomila - SFML developer

Ako

  • Newbie
  • *
  • Posts: 14
    • View Profile
Position of SubRect of a Sprite...
« Reply #2 on: June 19, 2008, 12:31:40 pm »
Put what in view space? The sprite? So I must translate/rotate/scale it, even if I don't want to? Isn't it in the default view space?

How to convert the mouse position to view space? And can I use the Contains() method then anyway?

I'm a very newb to this sorry :-/

Thanks!
Greets

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Position of SubRect of a Sprite...
« Reply #3 on: June 19, 2008, 01:11:39 pm »
Quote
Put what in view space? The sprite? So I must translate/rotate/scale it, even if I don't want to?

As the subrect is in local space, then yes you must do the conversion.

Quote
How to convert the mouse position to view space?

In the next version there will be a function for that.

Quote
And can I use the Contains() method then anyway?

Only if there's no rotation.
Laurent Gomila - SFML developer

Ako

  • Newbie
  • *
  • Posts: 14
    • View Profile
Position of SubRect of a Sprite...
« Reply #4 on: June 19, 2008, 01:25:47 pm »
Okay thanks!
Greets

 

anything