基本上我想要做的是将精灵的活动动画的引用存储为 Actor 类中的私有成员。我想使用参考,所以我不必多次实际创建动画,但我一直收到错误。
演员类声明:
class Actor
{
public:
Actor();
~Actor();
void setActiveAnimation(Animation anim);
void draw(sf::RenderWindow& win);
private:
sf::Sprite sprite;
MaJR::Animation& activeAnimation;
};
演员类实现:
Actor::Actor()
{
// constructor
}
Actor::~Actor()
{
// destructor
}
void Actor::setActiveAnimation(Animation anim)
{
activeAnimation = anim;
activeAnimation.gotoStart();
}
void Actor::draw(sf::RenderWindow& win)
{
sprite.setTexture(activeAnimation.getActiveFrame());
win.draw(sprite);
activeAnimation.nextFrame();
}
构建输出:
/home/mike/MaJR Game Engine/src/Actor.cpp||In constructor 'MaJR::Actor::Actor()':|
/home/mike/MaJR Game Engine/src/Actor.cpp|8|error: uninitialized reference member 'MaJR::Actor::activeAnimation' [-fpermissive]|
||=== Build finished: 1 errors, 0 warnings ===|