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

Author Topic: Localize mouse position  (Read 2032 times)

0 Members and 1 Guest are viewing this topic.

woskaz0n

  • Newbie
  • *
  • Posts: 14
    • View Profile
Localize mouse position
« on: December 23, 2008, 10:42:17 pm »
Hi everybody,

I want to find out if my mouse is about an area or an object (with other words, a sprite  :) ).
(this sprites are not made by myself!!!)

An example: Here the mouse can be about the Tile 1, 2 or about the empty space... the thing that could make it a bit different is, that I donĀ“t want to use fix coordinates in my source, like
Code: [Select]
(Cursor.GetPosition().x >= 200)

So, I tried a few things, but without any succes^^
Code: [Select]
if((Cursor.GetPosition().x == Sprite1.GetPosition().x) && (Cursor.GetPosition().y == Sprite1.GetPosition().y))
Why does it not work?

Thanks in advance!
Realism is what makes games suck. - Wouter van Oortmerssen

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Localize mouse position
« Reply #1 on: December 23, 2008, 11:16:31 pm »
With your condition, you need to point your mouse exactly on the point (Sprite1.GetPosition().x;Sprite1.GetPosition().y).

--> if (mouse.x >= sprite.x && mouse.x <= sprite.x + sprite.width && mouse.y >= sprite.y && mouse.y <= sprite.y + sprite.height)
SFML / OS X developer

 

anything