Page 1 of 1

initialising an object with parameters

PostPosted: Jun 28, 2002 @ 2:49pm
by Conan
My Sprite class contains an array of Rects dependant on the number of frames in the Sprite. I can get the array defined by declaring it in the header as:-
Rect *FrameArray and then initialising it in the function which also loads the image:-
FrameArray = new Rect[_f] ;
While this works what I wanted to do was set up the frame total in the constructor but my attempts to define a Sprite as a private variable at the bottom of MyGame kept failing with a 'constant' error so I just create a Sprite using an empty constructor and this works.

The question is how do I create an object with parameters available to the rest of the game code ( or is this not possible ). I don't see any examples anywhere of this happening.

PostPosted: Jun 28, 2002 @ 3:30pm
by BurningSheep
I'm not sure if this is what you mean, but you can pass parameters to the constructor like this:

MyObject obj(12, "Hello");

or

MyObject * obj;
obj = new MyObject(12, "Hello");

assuming the constructor of the MyObject class looks something like this:

MyObject::MyObject(int x, char * text)
{
// init stuff
}

PostPosted: Jun 28, 2002 @ 4:12pm
by Pam

C++ can be so cumbersome

PostPosted: Jun 28, 2002 @ 8:34pm
by Conan
Thanks Pam + Burning Sheep
Im doing similar to you Pam. It just seems odd that there's no way to define a class object with parameters inside 'PF'
I could cheat & make the first charater or two of the image name = the frame count & chop this out into a number at load time.

Docs wise I need to find out how much support for loading files from disk into a surface there is. If it wasn't for the Plasma demo I would not have realised that you could lead a .raw file for instance. Storing some big files on the PocketPC will cut down on download time during development.

The plasma demo is very interesting. I need my wife who is a maths teacher to explain the math. I need to work up some light based effects like lens flares & nebula for my game so I will be scouring the web for samples but unfortunately nowadays so much is based around OpenGL & DirectX. I also need some 3D so I'm looking at either embedding very basic support cribbed from the iPaq demo Jacco did or the complex option of merging PocketGL into PocketFrog. I think the linker would have a fit somehow.

Good weekend to all