Hi!
I am a bit confused with object initialization in my engine.
Imagine you have in your engine Main.cpp and 2 classes called : CMenu.cpp and CButton.
Each class contain one member function : (CButton) initButtonTexture() and (CMenu) initMenu().
Now in your Main.cpp you create 1 object called menu by using CMenu class : Cmenu menu;
This object will basically construct and display menu in window.
eg. menu.display()
The CButton object is used inside the CMenu class to create buttons. So Menu will contain buttons.
The CButton is #included in my CMenu header file but it is not included in Main.cpp. In Main.cpp I have only CMenu object constructed.
Now. lets say I want every button in my menu to be textured with different texture.
My question is… what is the correct way of initializing textures for these 2 objects. menu and button.
eg. for the button shoud I always pass from main.cpp in init() a string (path) eg. “img/button.tga” by using menu object eg. menu.initMenuTextures(“img/button.tga”) and pass hte path to menu and then from menu pass the path further to the button class eg. in menu I have an object button so I call button.initiButtonTexture( char* path) which passes the path to button class which will receive the path all the way from main and then it can load the texture. (thats how I’ve done it)
Is it correct way or you think that I should not be passing from main the path via menu eg menu.initMenu(“img/button.tga”) to button. ie. from main to menu and from menu to button but instead I should just specify the path (img/button.tga) inside the button class so I dont have to mess around with passing the path from main to menu and from menu to button. This way would save a bit more time but I think another problem would arise when for eg I would like to create a button with different texture. This way I wont be able to specify a different path from main init() when loadng textures. I would have go to my CButton class and edit the path in textureloader in order to laod different texture. unless I create two member functions in Button called
initButtonTex1()
{ loadtex( img/button1.tga); }
and initButtonTex2()
{ loadtex(img/button2.tga);}
and then call them from menu without specifying the path (parameterless) eg. menuInit(){ button1.initButtonTex1() ; button1.initButtonTex2()}
}
which doesn’t make sense to me.
Which way do you think guys is the correct one. Or how would you do?
thanks!
[This message has been edited by robert_s (edited 04-23-2002).]