This project has moved and is read-only. For the latest updates, please go here.

Circle Body Problems, Please help!

Topics: Developer Forum, User Forum
Dec 13, 2013 at 4:07 PM
Edited Dec 13, 2013 at 4:08 PM
I have created a circle body class, but in game my player body just passes through it. the circle will not move, only rotate.

however when i create the circle body just straight up, raw in the game1 load content method, without using a personalised class, it works. so im thinking i have done something wrong but i cant for the life of me spot it.

here are the two different implementations, the first is the class and its instance in the game1 class, THAT doesn't want to move the circle around or collide properly, the second is the classless implementation directly in the load content method of the game1 class.

    class CircleBody
    Texture2D Texture;
    Vector2 Origin;
    Vector2 Position;
    public Body Circle;

    public CircleBody(Texture2D texture, Vector2 position, World world)
        this.Texture = texture;
        this.Origin = new Vector2(this.Texture.Width / 2f, this.Texture.Height / 2f);
        this.Position = new Vector2(ConvertUnits.ToSimUnits(position.X), ConvertUnits.ToSimUnits(position.Y));
        Circle = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(56 / 2), 1f, this.Position);
        Circle.BodyType = BodyType.Dynamic;
        Circle.Restitution = 0.3f;
        Circle.Friction = 0.5f;

    public void Draw(SpriteBatch spriteBatch)
        spriteBatch.Draw(this.Texture, ConvertUnits.ToDisplayUnits(this.Position), null, Color.White, this.Circle.Rotation,
            this.Origin, 1f, SpriteEffects.None, 0f);
here is the above class instanced and implemented in the game1 class:

    CircleBody CircleBody;
    Texture2D CircleTexture;
Load Content Method:
CircleTexture = Content.Load<Texture2D>("Player");
CircleBody = new CircleBody(CircleTexture, new Vector2(400, 300), world);
it just doesn't work :(,

HOWEVER it works perfectly when I create it in a different way, as in not through my own class, but raw within the game1 class. here is the code.

 Texture2D playerTex;
 Vector2 playerOrigin;
 Body player;
LoadContent Method
playerTex = Content.Load<Texture2D>("Player"); // 
playerOrigin = new Vector2(playerTex.Width / 2f, playerTex.Height / 2f);
Vector2 playerPosition = ConvertUnits.ToSimUnits(screenCenter); 
player = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(56 / 2), 1f, playerPosition);
player.BodyType = BodyType.Dynamic;
player.Restitution = 0.3f;
player.Friction = 0.5f;
   spriteBatch.Draw(playerTex, ConvertUnits.ToDisplayUnits(player.Position), null, Color.White, player.Rotation,
                playerOrigin, 1f, SpriteEffects.None, 0f);
The first method through the class is obviously the cleaner and perfect way i want to implement the creation of a circle based body sprite combination, but i dont understand why the sprite is not moving, or collidable or seemingly alive in the simulation.

and i really dont see why it works raw in game1 class.

i really hope you can help!!! im sooooo stuck
Dec 14, 2013 at 5:51 PM
Unless you're manually updating the Position variable on the Circle class you need to change your draw method to reference the body

  spriteBatch.Draw(this.Texture, ConvertUnits.ToDisplayUnits(this.Circle.Position), null, Color.White, this.Circle.Rotation,
            this.Origin, 1f, SpriteEffects.None, 0f);
Dec 15, 2013 at 1:01 AM
Thank you so much.

dont know why my brain didn;t think to figure that out.

you are a legend!!! :)