I have a list of bullets that get shot from one side of the screen to the other. Whenever i "shoot" the cannon,
i use XML calls (reader, writer, ...) to create a ball from file, and add it to my list
GameObject newBall;
newBall = Content.Load<GameObject>(@"Data\\Ball");
newBall.Alive = true;
newBall.Position = robot.Position - newBall.Center;
newBall.Velocity = new Vector2(
(float)Math.Cos(robot.Rotation),
(float)Math.Sin(robot.Rotation)) *10.0f;
cannonShots.Add(newBall); // cannonShots is my List that contains the cannon Balls
I do it this way, so i can set the properties of each specific type of ball, weight, sound effects, etc,
without having to hard code them into my code. (Little balls, big balls, etc) (little bang, big bang, explosions, etc)
What i have noticed is that, ALL the cannonballs are pointing to the same memory location.
I may have multiple "cannonballs" in my list, but they are all pointing to the exact same instance.
So each time it updates, depending on how many instances there are in the list, it will update that
much faster. So if there are 3 cannonballs in the list, it updates 3 times.
And when my draw function draws them onto the screen, there is only 1 ball that gets drawn, despite my list
having multiple instances of cannonballs.
Note, i am learning XML, and applying it towards the 2D tutorial found on the site.
I know my XML reader writer, etc is working fine, because everything compiles, and the data loads properly, when
the content.load function gets called.
How can i load unique objects from XML, and also make sure they aren't all pointing to the same object?
Thanks so much for your help
If it ain't broke, it doesn't have enough features yet - Scott Adams, The Dilbert Principle