Farseer circle hangs where it's spawned

Posted by necrosmash on Game Development See other posts from Game Development or by necrosmash
Published on 2012-11-26T16:53:47Z Indexed on 2012/11/26 17:28 UTC
Read the original article Hit count: 186

Filed under:
|
|

I'm currently trying to simply spawn a circle in Farseer. However, it's stuck wherever I spawn it! The game is updating fine, as I can see the circle spinning in place when I spawn it because of how I currently have gravity set up (following code from Game1.cs):

// Initialise the screen center for use with
// the Level class
screenCenter = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f, graphics.GraphicsDevice.Viewport.Height / 2f);

 world = new World(new Vector2(20, 20));
 currentLevel = new Level1(screenCenter, circleSprite, groundSprite, ref world);

Level1 constructor:

public Level1(Vector2 screenCenter, Texture2D circleSprite, Texture2D groundSprite, ref World world)
    {
        player = new Player(ref world, screenCenter, circleSprite);
        ground = new Ground(ref world, screenCenter, groundSprite);
        listLevelItems = new List<LevelItem>();
        listLevelItems.Add(player);
        listLevelItems.Add(ground);
    }

Player constructor:

public Player(ref World world, Vector2 screenCenter, Texture2D sprite)
    {
        setSprite(sprite);
        setPosition((screenCenter / MeterInPixels) + new Vector2(0f, 0f));

        playerBody = BodyFactory.CreateCircle(world, 96f / (2f * MeterInPixels), 1f, playerPosition);
        getBody().BodyType = BodyType.Dynamic;

        // Ball bounce and friction
        getBody().Restitution = 0.3f;
        getBody().Friction = 0.5f;
    }

If I use a breakpoint and change the playerBody position while the game is halted, the ball does move, but stays fixed in its new location.

Any help would be greatly appreciated.

© Game Development or respective owner

Related posts about XNA

Related posts about c#