SFML community forums
Help => Window => Topic started by: Finn on September 28, 2010, 05:48:17 pm
-
I'm trying to do some dynamic drawing. Means: Everything that is on a position you can't see at the moment won't be displayed. For this purpose I'd like to ask, how to use the ConvertCoords() function. Without views I'd do:
bool DynamicWindow::IsInSight(const sf::Drawable &Drawable)
{
int X = Drawable.GetPosition().x;
int Y = Drawable.GetPosition().y;
if(X < 0 || X >= m_Width || Y < 0 || Y >= m_Height)//check if the Drawable can be seen
return false;
else
return true;
}
where m_Width and m_Height the size of the displayed window is. But this doesn'T work with views! Help please :P
-
No one knows how to do that? :shock:
-
You don't need convert coods. You are calculating if a point is inside the rectangle (0, 0, width, height). With views, you shoudl rather check if the point is insde the rectangle(view.x, view.y, view.x+view.width, view.y+view.height).
Hope this helps ;)
-
Thx :)
Works!
But with checking the position it's not as it should be.
I check the Position, so only the top left corner of the sprite.
Even though the sprite is in sight it isn't displayed because the position of the sprite is outside the view.
I tried something like this to get rid of this problem:
bool IsInSight(const sf::Drawable &Drawable, sf::View &View)
{
int X = Drawable.GetPosition().x;
int Y = Drawable.GetPosition().y;
int Width = Drawable.GetScale().x;
int Height = Drawable.GetScale().y;
sf::FloatRect Rect(X, Y, X+Width, Y+Height);
sf::FloatRect ViewRect = View.GetRect();
//check if the sprite is in the view
if(ViewRect.Intersects(Rect))
window.Draw(Drawable);
}
But it's just the same :-/ Suggestions?
Finn
-
When you have problems like this, try to print the values you are working with. If you print your Widht and Height you will notice that they are a value near 1.f.
That's because you are getting the scale percentage modifier of the sprite, not the width nor the height. You can't get those values from a sf::Drawable.
You can get the width and height of a sf::Sprite getting it's sf::Image and checking it's width and height.
-
Thx :) Dynamic drawing is only be used for sprites, so no problem :) But why doesn't it work with Drawables?
-
Thx :) Dynamic drawing is only be used for sprites, so no problem :) But why doesn't it work with Drawables?
Because you can't get the size of drawables. That's a base class object that just provides a virtual render function. Other objects derive from drawables and then they can be painted.