Again, sorry for the bad title, but hopefully it'll be understandable. Basically, I'm creating a class for animation and instead of limiting myself to just using OpenGL for more power I would also implement software rendering with the SDL library. First off lets start with the class I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class AnimationStrip
{
public:
AnimationStrip(string FramePrefix, int TotalFrames, float x, float y);
float GetFrameWidth();
float GetFrameHeight();
float GetX();
float GetY();
void UpdateAnimation(int DelayBetweenFrames);
void Render(Screen scr);
private:
float X, Y, CurrentFrameWidth, CurrentFrameHeight;
int NumberOfFrames;
};
I haven't actually created the constructor yet, but basically instead of creating two arrays of the images I'll be loading in the constructor which for OpenGL would be an array of GLuints and in SDL it would be an array of SDL_Surfaces, I want to know how to create one or the other depending on which is currently being used.
The problem is if I were to create one of these arrays it would have to be in the constructor once I determine if OpenGL is being used or not, but then the rest of the class wouldn't be able to use the variable because it'd be limited to the scope of the constructor. I also can't create the array without knowing how many frames (images) I'm actually loading which is determined by what is entered into the constructor.
So bottom line, is it possible to create variables in the constructor of a class that aren't limited to the scope of that constructor?
class AnimationStrip {
public:
virtual ~AnimationStrip() {} // This line is REALLY IMPORTANT!
// If you delete it, your derivated classes will not be able to call destructors!
virtualvoid Render(Screen&) = 0; // <- The derivated classes
// will create a Render function different from the base one.
// The base one isn't "associated" to SDL or OpenGL, make it
// undeclarable by itself.
// Also, add non-driver-dependent things like position, size and frames count here.
};
class SDLAnimationStrip : public AnimationStrip {
public:
virtualvoid Render(Screen& scr) {
// SDL Render Code goes Here.
}
// You can add SDL-dependent things here
};
class OGLAnimationStrip : public AnimationStrip {
public:
virtualvoid Render(Screen& scr) {
// OGL Render Code
}
// You can add OGL-dependent things here
};
When you are going to use them, you should use them like: