Trouble with Sprites

Topics: Developer Forum, Project Management Forum, User Forum
Apr 28, 2011 at 7:51 PM

Greetings everyone !


I have come across a problem, it involves sprites.

What my game does is that it uses my mouse clicks and the coordinates from the mouse movements to draw random shapes a la Crayon Physics. I have a List of Vertices for the shapes and then I have a List of Sprites for those shapes.

Like so,


I want to remove/erase the shapes by using the right click, I use the following code, where dynosprites is a List of sprites.

#region Delete Objects

                if (input.IsNewMouseButtonPress(MouseButtons.RightButton))

                    mouseClickFixture = World.TestPoint(ConvertUnits.ToSimUnits(input.Cursor));

                    if (mouseClickFixture != null && dynoSprites.Count > 0)


But the problem is that the body gets deleted but the sprite does not ! (I've tried with a lot of shapes and variables)

Like so,

(Here the right most object was the one to be deleted)


I draw this using SpriteBatches, as shown here


if (dynoPolys.Count > 0)
           for (int i = 0; i < dynoPolys.Count; i++)
                        ScreenManager.SpriteBatch.Draw(dynoSprites[i].texture, ConvertUnits.ToDisplayUnits(dynoPolys[i].Position), null, Color.White, dynoPolys[i].Rotation, dynoSprites[i].origin, 1f, SpriteEffects.None, 0f);


What seems to be the error ? I have tried a lot of different approaches all lead to a dead end !


Another problem is that when I minimize the game , all the sprites are lost ! Like so,


Please help !

Best Regards and Thanks in Advance !