Hey
I'm trying to implement collision detection for a project. So far, my idea has been to add all objects that are added into a scene into an array of objects. My question is, as in the title, can I add an object to said array in its constructor?
I've tried like this
Object::Object ()
{
pos_x = 0; pos_y = 0; velocity = 0; direction = 0;
objectArray [numObjects] = this.Object;
numObjects++
}
and this
Object::Object ()
{
pos_x = 0; pos_y = 0; velocity = 0; direction = 0;
objectArray [numObjects] = this;
numObjects++
}
But neither worked, and I'm having trouble figuring out exactly how I would do it properly, if it's at all possible.
Also, objectArray is just a pointer to an object, and I've had trouble with pointers before (and probably will for a while).
int numObjects = 0;
Object *objectArray;
Any help would be appreciated. I also realise that there are probably better ways to keep track of all the objects, or to go about handling collision detection in general. So any help with this topic, or just collision detection in general would be great.
Thanks.