C
Chocawok
Some of the classes in my app are graphical.
To encapsulate the graphical side of things I had created a class called
"sprite" which holds a bit map and knows how to draw itself etc.
The classes that are graphical contain a sprite object.
MyClass
{
private:
Sprite this_objects_sprite;
}
The sprite class requires a pointer to a "video surface". There is no way
around this. The pointer is required for the construction and drawing of the
sprite object.
My problem is this:
This design means that I have to pass the pointer to the video surface to
myclass in its constructor, e.g.
MyClass
{
private:
Sprite this_objects_sprite;
public:
MyClass(VideoSurface* s)
{
this_objects_sprite = new Sprite(VideoSurface* s);
...
...
}
....
....
}
Obviously this means all my graphical objects are tightly coupled to the
graphics system I am using. Also obviously (I think) is that this is
undesireable.
I was thinking of maybe arranging things so that the sprite is not
automatically instantiated in the container objects constructor.
That is, I construct my object THEN call a function to construct the objects
sprite, e.g.
MyClass c = new MyClass();
c.CreateSprite(VideoSurface* s);
But then this raised other issues like, how do I handle what happens if i
try to draw the object before creating its sprite.
Any thoughts on this?
Dean
To encapsulate the graphical side of things I had created a class called
"sprite" which holds a bit map and knows how to draw itself etc.
The classes that are graphical contain a sprite object.
MyClass
{
private:
Sprite this_objects_sprite;
}
The sprite class requires a pointer to a "video surface". There is no way
around this. The pointer is required for the construction and drawing of the
sprite object.
My problem is this:
This design means that I have to pass the pointer to the video surface to
myclass in its constructor, e.g.
MyClass
{
private:
Sprite this_objects_sprite;
public:
MyClass(VideoSurface* s)
{
this_objects_sprite = new Sprite(VideoSurface* s);
...
...
}
....
....
}
Obviously this means all my graphical objects are tightly coupled to the
graphics system I am using. Also obviously (I think) is that this is
undesireable.
I was thinking of maybe arranging things so that the sprite is not
automatically instantiated in the container objects constructor.
That is, I construct my object THEN call a function to construct the objects
sprite, e.g.
MyClass c = new MyClass();
c.CreateSprite(VideoSurface* s);
But then this raised other issues like, how do I handle what happens if i
try to draw the object before creating its sprite.
Any thoughts on this?
Dean