SFML community forums
General => Feature requests => Topic started by: Tank on August 02, 2009, 07:31:59 pm
-
Hey.
Before SFML2, sf::View got some methods like GetRect() and SetFromRect(). SetFromRect() is still available through the new Reset(), but GetRect() isn't. That's probably because of the underlying data storage, since you're saving the view's center and not the rectangle anymore.
Is it possible to have a GetRect() again or at least a GetPosition() and SetPosition()? For me, it would be easier for some map movements. I'm currently doing the calculations by myself (get the center and subtract half of the view's size), but would rather see it in SFML itself.
Greetings
-
It's no longer possible to retrieve an axis-aligned rectangle because of the new rotation.
-
That's reasonable. :(
Maybe it's not the right place in the feature requests board, but I've used sf::View to provide pixel-wise movements for a 2D tilemap, which was a superb future of the old sf::View's behaviour. When the map is moved by 1 pixel, I just move the sf::View respectively -- mainly to avoid setting the positions of all visible sf::Sprites.
Any suggestions on making this still possible?
Edit: I just remember I've used the sf::View "scrolling" for a side scroller game. This wouldn't be possible anymore, too. I'd love to have a replacement for that, if possible.
Edit²: After some thinking I guess it's still possible by saving an sf::FloatRect myself, adding offsets to it and stuffing it into sf::View::Render(). Am I right that this will reset the sf::View exactly to the rectangle I provide? (no chance to test it atm)
-
Oh, so you're just talking about moving the view? Of course this is still possible, use SetCenter / GetCenter ;)
-
That solves the problem. It has been just a bit weird to set a center instead of a rectangle/border position. But since rotation is taken into account (which is a killer feature, since it enables changing my 2d tilemap into an isometric map with ease!), this absolutely makes sense.
Thanks. :)
-
By the way, I guess it's okay if there aren't too many redundant methods (GetRect <-> GetCenter, GetSize), since such a functionality can easily be implemented by an own, global function... ;)
-
True, but the public interface must (not should) be consistent. Therefore if class A has a rect and provides a GetRect() method, so should class X if it has a rect and it's somewhat useful for the developer.
This is one of the smaller things that can really disturb me while programming. Class A uses SetPosition( sf::Vector2i &foo ) and class B uses SetPosition( int x, int y ). I could argue that you can easily create such functions yourself, but that doesn't help anybody.
-
Concerning GetRect(), I don't fully agree with you. The existence of a GetRect() method shouldn't depend too much on the internal implementation. For example, why should sf::String have a GetRect() method, while sf::Sprite has none? A bounding rectangle obviously makes sense at sprites, too. All this stuff could be made much easier if the implementation were more uniform.
If those classes represent their geometry by three vectors (namely position, origin and size) and support respective getter and setter functions, the interface will be more consistent. This would allow to program generically and write a single function template which can be applied to all objects meeting those requirements:
template <typename RectangularObject>
sf::FloatRect GetBoundingRect(const RectangularObject& Obj)
{
sf::Vector2f LeftUpper = Obj.GetPosition() - Obj.GetOrigin();
sf::Vector2f RightLower = LeftUpper + Obj.GetSize();
return sf::FloatRect(LeftUpper.x, LeftUpper.y, RightLower.x, RightLower.y);
}
-
I like that approach, nothing to complain, sorry. ;)
-
The interface will be much more consistent in SFML 2.
-
Accessing View.Rotation causes an EntryPointNotFoundException in .NET.
I didn't investigate any further yet - maybe the export is missing?
I just wanted you to know in case you didn't already. :wink:
-
Accessing View.Rotation causes an EntryPointNotFoundException in .NET.
I didn't investigate any further yet - maybe the export is missing?
I just wanted you to know in case you didn't already
I didn't know.
SFML.Net is not tested a lot, so I need as much feedback as possible. Thank you :)
-
This should be fixed now.