This project is read-only.

Tutorial12 - Create second car

Dec 27, 2009 at 2:29 PM


I would like to create a second car and I have add the line

RaceCar car2 = VehicleCreator.AddRaceCar(scene, parentTransNode);

in private void CreateObjects()

But I get a error message “An element with the same key has already been added.” in base.Draw(gameTime).


Is this a wrong way to create a second car? Can you help me?


Thanks in advance 

Dec 27, 2009 at 8:21 PM

We don't allow a node with the exact same name to be added to the scene graph.

In this case, in the AddRaceCar method, it creates a geometry node with a name "Race Car".

If you call this method again to create another car, it will try to add another geometry node with "Race Car", so it throws an exception.

Just modify the AddRaceCar method to take different name, and it should work fine.


Dec 27, 2009 at 8:21 PM

Same for the tires geometry node as well.

Dec 27, 2009 at 8:43 PM

Hello Ohan,

I have modified the name and its work.
Thanks  for your help.