I'm not really sure what you mean, but something like: ```c++ class Animation { public: void pla

I'm not really sure what you mean, but something like:
c++
class Animation {
public:
void play();
// other animation-related methods and properties
};

class Character {
private:
Animation animation; // animation object for the character
public:
Character();
// other character-related methods and properties
};

class Obstacle {
private:
Animation animation; // animation object for the obstacle
public:
Obstacle();
// other obstacle-related methods and properties
};
c++
class Animation {
public:
void play();
// other animation-related methods and properties
};

class Character {
private:
Animation animation; // animation object for the character
public:
Character();
// other character-related methods and properties
};

class Obstacle {
private:
Animation animation; // animation object for the obstacle
public:
Obstacle();
// other obstacle-related methods and properties
};
Now whenever you need to animate a Character or an Obstacle, you can simply call the play() method. E.g.
c++
Character.animation.play()
c++
Character.animation.play()
11 Replies
Dumb Bird
Dumb BirdOP12mo ago
I'm not too sure what you're asking, if this isn't what you want let me know and I can try to help you
Enceladus
Enceladus12mo ago
Hmm yeah that’s the idea, however when I want to put the parameters of the animation variable it doesn’t work And I saw you could use the Anim object as a pointer but I don’t know if it’s useful in my case
Dumb Bird
Dumb BirdOP12mo ago
Huh? If you want to put parameters into the animation object you'd need to make a class constructor
c++
class Animation {
private:
// animation parameters
float animationSpeed;
bool loop;
public:
// constructor with parameters
Animation(float speed, bool loopAnimation) : animationSpeed(speed), loop(loopAnimation) {}

void animate();
// other animation-related methods and properties
};

class Character {
private:
Animation animation;
public:
// constructor with parameters
Character(float animSpeed, bool loopAnim) : animation(animSpeed, loopAnim) {}

// other character-related methods and properties
};

class Obstacle {
private:
Animation animation;
public:
// constructor with parameters
Obstacle(float animSpeed, bool loopAnim) : animation(animSpeed, loopAnim) {}

// other obstacle-related methods and properties
};
c++
class Animation {
private:
// animation parameters
float animationSpeed;
bool loop;
public:
// constructor with parameters
Animation(float speed, bool loopAnimation) : animationSpeed(speed), loop(loopAnimation) {}

void animate();
// other animation-related methods and properties
};

class Character {
private:
Animation animation;
public:
// constructor with parameters
Character(float animSpeed, bool loopAnim) : animation(animSpeed, loopAnim) {}

// other character-related methods and properties
};

class Obstacle {
private:
Animation animation;
public:
// constructor with parameters
Obstacle(float animSpeed, bool loopAnim) : animation(animSpeed, loopAnim) {}

// other obstacle-related methods and properties
};
Enceladus
Enceladus12mo ago
Wait I’m gonna show you what I mean here's a part of Animation (also every objects i'm talking about are isolated in separated files)
Enceladus
Enceladus12mo ago
No description
Enceladus
Enceladus12mo ago
and in the Character, I have this
No description
Enceladus
Enceladus12mo ago
so I made an Animation variable: m_anim
Enceladus
Enceladus12mo ago
however I can't put the parameters in the anim
No description
Enceladus
Enceladus12mo ago
hmm wait the error is gone? does it mean that it works? @earth's bird because I got an errordoing that previously but I think it's vscode going crazy, it's sometimes happening...
Dumb Bird
Dumb BirdOP12mo ago
Well nothing I see is really wrong in your code But show me the error when compiling
Enceladus
Enceladus12mo ago
I didn't compiled yet, it was trusting the vscode error which now disapeared lmao

Did you find this page helpful?