Box2DX.Dynamics.Body.CreateFixture C# (CSharp) Method

CreateFixture() public method

Creates a fixture and attach it to this body. @warning This function is locked during callbacks.
public CreateFixture ( FixtureDef def ) : Fixture
def FixtureDef The fixture definition.
return Fixture
		public Fixture CreateFixture(FixtureDef def)
		{
			Box2DXDebug.Assert(_world._lock == false);
			if (_world._lock == true)
			{
				return null;
			}

			BroadPhase broadPhase = _world._broadPhase;

			Fixture fixture = new Fixture();
			fixture.Create(broadPhase, this, _xf, def);

			fixture._next = _fixtureList;
			_fixtureList = fixture;
			++_fixtureCount;

			fixture._body = this;

			return fixture;
		}

Usage Example

Example #1
0
        public Projectile(Player creator, float x, float y, float width, float height)
            : base(creator, 0, 0)
        {
            /* Create New Projectile Body */
            BodyDef def = new BodyDef();
            def.IsBullet = true;
            def.Position = creator.body.GetPosition() + new Vec2(x, y);
            projectile = creator.body.GetWorld().CreateBody(def);

            /* Create a fixture for the projectile */
            PolygonDef fixdef = new PolygonDef();
            fixdef.Density = 1.0f;
            fixdef.SetAsBox(width / 2, height / 2);
            fixdef.Filter.GroupIndex = creator.ID;
            fixture = projectile.CreateFixture(fixdef);
            fixture.Filter.CategoryBits = 0x0004;
            fixture.Filter.MaskBits = 0xFFFF;

            /* Made a 2nd fixture, one to observe all collisions */
            fixdef.IsSensor = true;
            fix2 = projectile.CreateFixture(fixdef);
            fix2.UserData = this;

            /* Finally, give this projectile some mass */
            projectile.SetMassFromShapes();

            /* Also, make sure we destroy the projectile when it is time */
            this.OnDestroy += Cleanup;
        }
All Usage Examples Of Box2DX.Dynamics.Body::CreateFixture