SFML community forums

Help => Graphics => Topic started by: Phyton on September 27, 2019, 04:55:53 pm

Title: Sprite doesn't transform in an inherited class
Post by: Phyton on September 27, 2019, 04:55:53 pm
Hi Forum,
i faced a problem with my inherited class and sf::sprite.
I have a custom class, that inherits from sf::Drawable and sf::Transformable
Here it is:
class DrawableObject : public sf::Drawable,public sf::Transformable
{
public:
        DrawableObject();
        ~DrawableObject();
        bool loadImage(std::string);
        sf::FloatRect getFloatRect();

private:
        sf::Texture m_texture;
        sf::Sprite m_sprite;
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                states.transform *= getTransform();
                target.draw(m_sprite, states);
        }
};
 
It works quite fine...i can render and move as expected !
But now i wanted to implement collision. I read that sf::transformable has no getGlobalBounds() function so
i thought that i just use the getGlobalBounds method from my sprite(m_sprite), but every value from the position to the FloatRect is nonsense(doesnt fit the values directly obtained from my class) !

Is there a way i can apply every tranformation i made to the class also to the Sprite ?
Thanks
Title: Re: Sprite doesn't transform in an inherited class
Post by: eXpl0it3r on September 27, 2019, 08:03:25 pm
You can transform the sprite position with the point transformation of an sf::Transform.
It would probably be easier (and cleaner) to just calculate the bounding box yourself.
Title: Re: Sprite doesn't transform in an inherited class
Post by: Phyton on September 28, 2019, 09:24:08 am
So i did write my own getGloabalBounds and it works good.
Thanks !