This project is read-only.
3
Vote

Setting gravity on PhysicsCanvas does not work and _gravityVertical gets default initialized with 10

description

The setters for GravityHorizontal and GravityVertical have no meaning in the current context. When creating an PhysicsCanvas object the world gets created with the default values. The world never gets updated when you set those values. The only way is to do it in code behind and setting it directly on the world/Simulator.

i propose an update on the setters:
    private int _gravityHorizontal = 0;
    public int GravityHorizontal
    {
        get { return _gravityHorizontal; }
        set
        {
            if (_gravityHorizontal != value)
            {
                _gravityHorizontal = value;
                UpdateGravity();
            }
        }
    }

    private int _gravityVertical = 0;
    public int GravityVertical
    {
        get { return _gravityVertical; }
        set 
        {
            if (_gravityVertical != value)
            {
                _gravityVertical = value;
                UpdateGravity();
            }
        }
    }

    private void UpdateGravity()
    {
        Simulator.Gravity = new xna.Vector2(GravityHorizontal, GravityVertical);
    }

comments

jetchopper wrote Jun 8, 2016 at 2:39 PM

Here's the solution:
        public MainPage()
        {
            this.InitializeComponent();
            cnvGame.Simulator.Gravity = Vector2.Zero;
            //some other stuff
        }
Where Vector2 is Horizontal and Vertical gravities.
cnvGame is PhysicsCanvas.

This example removes gravity like in the open space :3
Cheers!