Tutorial12 - Create second car

Dec 27, 2009 at 1:29 PM

Hello,

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 

Coordinator
Dec 27, 2009 at 7: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.

Ohan

Coordinator
Dec 27, 2009 at 7:21 PM

Same for the tires geometry node as well.

Dec 27, 2009 at 7:43 PM

Hello Ohan,

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