This site is no longer active and is available for archival purposes only. Registration and login is disabled.

initialising an object with parameters


initialising an object with parameters

Postby Conan » Jun 28, 2002 @ 2:49pm

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.
What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Postby BurningSheep » Jun 28, 2002 @ 3:30pm

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
}
Do you want custom Snails levels? Click
User avatar
BurningSheep
pm Insider
 
Posts: 1226
Joined: Apr 12, 2002 @ 11:49pm
Location: The Netherlands


Postby Pam » Jun 28, 2002 @ 4:12pm

All the easy problems have been solved.
User avatar
Pam
pm Insider
 
Posts: 449
Joined: Jan 24, 2002 @ 10:30pm
Location: Ohio


C++ can be so cumbersome

Postby Conan » Jun 28, 2002 @ 8:34pm

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
What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Return to PocketFrog & PocketHAL


Sort


Forum Description

SDKs for fast and robust device-independent access to Pocket PC display hardware.

Moderators:

sponge, Kzinti

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron