23
« on: April 25, 2011, 03:37:21 am »
Just wondering if there was a function like sprite.getrect or image.getrect. similar to the method a view has. Well, I know there is no function but I guess is there a simple implementation? I'm trying to set a boundary for my camera by using the limits of a large level background sprite.
Isn't a sprite just a rectangle with an image?
heres what I've been trying to do currently with little success:
Pseudo code:
Here I try to create my own rectangle from the dimensions of a sprite. It will not compile though and says there is no matching function for call to sf::shape::rectangle. I assume its because an sf::shape is not at all an sf::rect.
Engine_Class{
sf::Rect <float> CameraBounds = sf::Shape::Rectangle(0,sprite_width,0,sprite_height);
Cam1.SetBounds(CameraBounds);
}
This next part should (theoretically) work if I could just come up with a rectangle lol!
Camera_Class{
sf::Rect <float> myBoundary;
void Camera::SetBounds(sf::Rect <float> CameraBounds){
myBoundary = CameraBounds;
}
bool Camera::Within_Bounds(){
if (ViewPort.GetRect().Left < myBoundary.Left) return false;
if (ViewPort.GetRect().Right > myBoundary.Right) return false;
if (ViewPort.GetRect().Top < myBoundary.Top) return false;
if (ViewPort.GetRect().Bottom > myBoundary.Bottom) return false;
return true;
}
}
any suggestions/thoughts/advice?