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

Author Topic: sf::View offset?  (Read 1252 times)

0 Members and 1 Guest are viewing this topic.

fatum

  • Newbie
  • *
  • Posts: 47
    • MSN Messenger - bowsers7@hotmail.com
    • AOL Instant Messenger - therealblah569
    • View Profile
    • http://boards.psynetfm.com
sf::View offset?
« on: August 28, 2011, 08:12:41 am »
Currently I'm working with this:
Code: [Select]

if (event.MouseButton.Button == 0)
{
for (int i = 0; i < blocks.size(); i++)
{
sf::Vector2f pos = blocks[i].GetPosition();

if (event.MouseButton.X >= pos.x && event.MouseButton.X < pos.x + 32 &&
event.MouseButton.Y >= pos.y && event.MouseButton.Y < pos.y + 32)
{
blocks.erase(blocks.begin() + i);
break;
}
}
}


Which works pretty well!  However, whenever I alter the position of my "camera" view, of course it doesn't work anymore.  Is there an offset I could apply to the condition to correct the problem?

Also, would it be better to check sprite.GetPosition().X and .Y instead of creating a Vector2f each time?  Or is it not really too significant?

Thanks for any help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::View offset?
« Reply #1 on: August 28, 2011, 09:19:34 am »
Use RenderWindow::ConvertCoords.

Quote
Also, would it be better to check sprite.GetPosition().X and .Y instead of creating a Vector2f each time? Or is it not really too significant?

I don't think it is significant at all ;)
Laurent Gomila - SFML developer

fatum

  • Newbie
  • *
  • Posts: 47
    • MSN Messenger - bowsers7@hotmail.com
    • AOL Instant Messenger - therealblah569
    • View Profile
    • http://boards.psynetfm.com
sf::View offset?
« Reply #2 on: August 28, 2011, 09:34:52 am »
Thanks!  That's exactly what I was going for.  If anyone in the future is looking for a solution to a similar problem:

Code: [Select]

sf::Vector2f MousePos = App.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, camera);

if (MousePos.x >= pos.x && MousePos.x < pos.x + 32 &&
       MousePos.y >= pos.y && MousePos.y < pos.y + 32)

 

anything