基本上我想要做的是将精灵的活动动画引用作为Actor类中的私有成员变量进行存储。我想使用引用,这样就不必多次创建动画,但我一直收到错误信息。
Actor类声明:
Actor类声明:
class Actor
{
public:
Actor();
~Actor();
void setActiveAnimation(Animation anim);
void draw(sf::RenderWindow& win);
private:
sf::Sprite sprite;
MaJR::Animation& activeAnimation;
};
Actor类的实现:
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 ===|