Hi all.
Which function must I overload in my class derived from sf::Sprite to keep that drawing behavior for RenderWindow::Draw() function just like the same as for Sprite. you know...
I mean how to keep behavior of my class like that
sf::RenderWindow App(/*init there*/);
sf::Sprite MySprite(); //let's count this sprite as fully initialized
App.Draw(MySprite);
But for my derived class.
To make the discussion more objective here is my class(es) code:
class Gun : public sf::Sprite
{
public:
Gun(const sf::Vector2f& Position, float Rotation=0, std::string texture=Options::Gun::Texture)
{
Texture.LoadFromFile(texture);
sf::Sprite::SetImage(Texture);
sf::Sprite::SetPosition(Position);
sf::Sprite::SetCenter(Options::Gun::Center);
sf::Sprite::SetRotation(Rotation);
}
void AimAt(const sf::Vector2f& Mouse)
{
sf::Vector2f Position = sf::Sprite::GetPosition();
float angle = std::atan2(Mouse.y - Position.y, Mouse.x - Position.x)*rad; // угол наклона
sf::Sprite::SetRotation(270 - angle);
}
private:
sf::Image Texture;
float VecLength(const sf::Vector2f& first, const sf::Vector2f& second)
{
return std::sqrt (std::pow( (second.x-first.x) ,2) + std::pow( (second.y-first.y) ,2));
}
};
class Tank : public sf::Sprite
{
public:
Tank(const sf::Vector2f& Position, float Rotation=0, std::string texture=Options::Tank::Texture) : Cannon(Options::Tank::GunPlace, Rotation)
{
Texture.LoadFromFile(texture);
sf::Sprite::SetImage(Texture);
sf::Sprite::SetPosition(Position);
sf::Vector2f PureCenter(Texture.GetWidth()/2 , Texture.GetHeight()/2);
sf::Sprite::SetCenter(PureCenter);
sf::Sprite::SetRotation(Rotation);
}
Gun& GetGun(void)
{
return Cannon;
}
void Simulate(const sf::Vector2f& Mouse)
{
}
private:
Gun Cannon;
sf::Image Texture;
};
As you can see I need my Tank class to Draw both itself's sprite and the cannon's sprite at the request of drawning the Tank sprite...
So which functions and how must I overload?
I guess it's some of Sprite::Draw() or Sprite::Render() functions.
Forehand thank you. And sorry for my bad English =(