Ok, my engine developement has finally reached the stage of mass game object programming. All the objects in the game are deveried from the class 'cls_object', which looks like this:
This way i can add any offspring of cls_object to my object vector, which is of type 'cls_object*'. Next I made my first offspring of 'cls_object' called 'cls_guiElement' that
looks like this:
So I was all excited and I hit compile, but it didn't work like it shoud, the image wasnt being rendered and setPropert() was failing. So i did some debuging and found that when i call any of 'cls_guiElement' functions, it still refers back to the empty ones declared in 'cls_object'. Shouldn't the offsprings functions replace the ancestors? One more thing that may help, heres how i'm adding objects and calling their methods in my object vector:
Code:
class cls_object{
public:
id id;
std::string alias;
cls_renderer* pRenderer;
public:
cls_object();
~cls_object();
void update();
void render();
void onLoad();
int setProperty(const char* name, const char* value);
};
//-----------------------------------
cls_object::cls_object(){
}
//-----------------------------------
cls_object::~cls_object(){
}
//-----------------------------------
void cls_object::update(){
}
//-----------------------------------
void cls_object::render(){
}
//-----------------------------------
void cls_object::onLoad(){
}
//-----------------------------------
int cls_object::setProperty(const char* name, const char* value){
return 1;
}
This way i can add any offspring of cls_object to my object vector, which is of type 'cls_object*'. Next I made my first offspring of 'cls_object' called 'cls_guiElement' that
looks like this:
Code:
class cls_guiElement : public cls_object{
public:
int top;
int left;
int width;
int height;
std::string image;
int opacity;
bool bgTransparent;
bool visible;
private:
cls_image* pImage;
RECT rect;
POINT point;
public:
cls_guiElement();
void render();
void onLoad();
int setProperty(const char* name, const char* value);
};
//-----------------------------------
cls_guiElement::cls_guiElement(){
top = 0;
left = 0;
width = 0;
height = 0;
image = "";
opacity = 100;
bgTransparent = 0;
pImage = 0;
visible = 1;
}
//-----------------------------------
void cls_guiElement::onLoad(){
if (image != "") pImage = pRenderer->imageCache[pRenderer->queryImage(image.c_str())];
rect.top = top;
rect.left = left;
if (pImage){
width = pImage->width;
height = pImage->height;
}
rect.bottom = top + height;
rect.right = left + width;
point.x = left;
point.y = top;
}
//-----------------------------------
void cls_guiElement::render(){
if (visible){
if (pImage){
if (bgTransparent){
}else{
pRenderer->blt(pImage->surface, &rect, 1, &point);
}
}
}
}
//-----------------------------------
int cls_guiElement::setProperty(const char* name, const char* value){
if (!strcmp(name, "image")){
image = value;
onLoad();
return 0;
}
return 1;
}
So I was all excited and I hit compile, but it didn't work like it shoud, the image wasnt being rendered and setPropert() was failing. So i did some debuging and found that when i call any of 'cls_guiElement' functions, it still refers back to the empty ones declared in 'cls_object'. Shouldn't the offsprings functions replace the ancestors? One more thing that may help, heres how i'm adding objects and calling their methods in my object vector:
Code:
std::vector <cls_object*> objects;
objects.push_back(new cls_guiElement);
objects[i]->render();