Trouble with Sprites

Topics: Developer Forum, Project Management Forum, User Forum
Apr 28, 2011 at 8: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,

http://i53.tinypic.com/2qv5xrq.png

 

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)
                    {
                        World.RemoveBody(mouseClickFixture.Body);
                        dynoSprites.RemoveAt(mouseClickFixture.Body.BodyId);
                    }
                }

#endregion

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,

http://i55.tinypic.com/1tjyna.png

(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,

http://i52.tinypic.com/vqhegn.png

 

Please help !

Best Regards and Thanks in Advance !