本文整理汇总了C#中Body.CreateFixture方法的典型用法代码示例。如果您正苦于以下问题:C# Body.CreateFixture方法的具体用法?C# Body.CreateFixture怎么用?C# Body.CreateFixture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body.CreateFixture方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Breakable
public Breakable()
{
// Ground body
{
BodyDef bd = new BodyDef();
Body ground = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
shape.SetAsEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
// Breakable dynamic body
{
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = new Vector2(0.0f, 40.0f);
bd.angle = 0.25f * Settings.b2_pi;
_body1 = _world.CreateBody(bd);
_shape1 = new PolygonShape();
_shape1.SetAsBox(0.5f, 0.5f, new Vector2(-0.5f, 0.0f), 0.0f);
_piece1 = _body1.CreateFixture(_shape1, 1.0f);
_shape2 = new PolygonShape();
_shape2.SetAsBox(0.5f, 0.5f, new Vector2(0.5f, 0.0f), 0.0f);
_piece2 = _body1.CreateFixture(_shape2, 1.0f);
}
_break = false;
_broke = false;
}
示例2: ContinuousTest
public ContinuousTest()
{
{
BodyDef bd = new BodyDef();
bd.position = new Vector2(0.0f, 0.0f);
Body body = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
shape.SetAsEdge(new Vector2(-10.0f, 0.0f), new Vector2(10.0f, 0.0f));
body.CreateFixture(shape, 1.0f);
shape.SetAsBox(0.2f, 1.0f, new Vector2(0.5f, 1.0f), 0.0f);
body.CreateFixture(shape, 1.0f);
}
#if true
{
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = new Vector2(0.0f, 20.0f);
//bd.angle = 0.1f;
PolygonShape shape = new PolygonShape();
shape.SetAsBox(2.0f, 0.1f);
_body = _world.CreateBody(bd);
_body.CreateFixture(shape, 1.0f);
Launch();
}
#else
{
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = new Vector2(0.0f, 0.5f);
Body body = _world.CreateBody(bd);
CircleShape shape = new CircleShape();
shape._p = new Vector2Zero();
shape._radius = 0.5f;
body.CreateFixture(shape, 1.0f);
//bd.bullet = true;
bd.position = new Vector2(0.0f, 10.0f);
body = _world.CreateBody(bd);
body.CreateFixture(shape, 1.0f);
body.SetLinearVelocity(new Vector2(0.0f, -100.0f));
}
#endif
}
示例3: ShapeEditing
public ShapeEditing()
{
{
BodyDef bd = new BodyDef();
Body ground = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
shape.SetAsEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
BodyDef bodydef = new BodyDef();
bodydef.type = BodyType.Dynamic;
bodydef.position = new Vector2(0.0f, 10.0f);
_body = _world.CreateBody(bodydef);
PolygonShape shape2 = new PolygonShape();
shape2.SetAsBox(4.0f, 4.0f, new Vector2(0.0f, 0.0f), 0.0f);
_fixture1 = _body.CreateFixture(shape2, 10.0f);
_fixture2 = null;
}
示例4: Step
public override void Step(Framework.Settings settings)
{
base.Step(settings);
_debugDraw.DrawString(50, _textLine, "Press: (,) to launch a bullet.");
if (_stepCount == 300)
{
if (_bullet != null)
{
_world.DestroyBody(_bullet);
_bullet = null;
}
{
CircleShape shape = new CircleShape();
shape._radius = 0.25f;
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 20.0f;
fd.restitution = 0.05f;
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.bullet = true;
bd.position = new Vector2(-31.0f, 5.0f);
_bullet = _world.CreateBody(bd);
_bullet.CreateFixture(fd);
_bullet.SetLinearVelocity(new Vector2(400.0f, 0.0f));
}
}
_textLine += 15;
}
示例5: Keyboard
public override void Keyboard(KeyboardState state, KeyboardState oldState)
{
if (state.IsKeyDown(Keys.OemComma) && oldState.IsKeyUp(Keys.OemComma))
{
if (_bullet != null)
{
_world.DestroyBody(_bullet);
_bullet = null;
}
{
CircleShape shape = new CircleShape();
shape._radius = 0.25f;
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 20.0f;
fd.restitution = 0.05f;
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.bullet = true;
bd.position = new Vector2(-31.0f, 5.0f);
_bullet = _world.CreateBody(bd);
_bullet.CreateFixture(fd);
_bullet.SetLinearVelocity(new Vector2(400.0f, 0.0f));
}
}
}
示例6: TheoJansen
TheoJansen()
{
_offset = new Vector2(0.0f, 8.0f);
_motorSpeed = 2.0f;
_motorOn = true;
Vector2 pivot = new Vector2(0.0f, 0.8f);
// Ground
{
BodyDef bd = new BodyDef();
Body ground = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
shape.SetAsEdge(new Vector2(-50.0f, 0.0f), new Vector2(50.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
shape.SetAsEdge(new Vector2(-50.0f, 0.0f), new Vector2(-50.0f, 10.0f));
ground.CreateFixture(shape, 0.0f);
shape.SetAsEdge(new Vector2(50.0f, 0.0f), new Vector2(50.0f, 10.0f));
ground.CreateFixture(shape, 0.0f);
}
// Balls
for (int i = 0; i < 40; ++i)
{
CircleShape shape = new CircleShape();
shape._radius = 0.25f;
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = new Vector2(-40.0f + 2.0f * i, 0.5f);
Body body = _world.CreateBody(bd);
body.CreateFixture(shape, 1.0f);
}
// Chassis
{
PolygonShape shape = new PolygonShape();
shape.SetAsBox(2.5f, 1.0f);
FixtureDef sd = new FixtureDef();
sd.density = 1.0f;
sd.shape = shape;
sd.filter.groupIndex = -1;
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = pivot + _offset;
_chassis = _world.CreateBody(bd);
_chassis.CreateFixture(sd);
}
{
CircleShape shape = new CircleShape();
shape._radius = 1.6f;
FixtureDef sd = new FixtureDef();
sd.density = 1.0f;
sd.shape = shape;
sd.filter.groupIndex = -1;
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = pivot + _offset;
_wheel = _world.CreateBody(bd);
_wheel.CreateFixture(sd);
}
{
RevoluteJointDef jd = new RevoluteJointDef();
jd.Initialize(_wheel, _chassis, pivot + _offset);
jd.collideConnected = false;
jd.motorSpeed = _motorSpeed;
jd.maxMotorTorque = 400.0f;
jd.enableMotor = _motorOn;
_motorJoint = (RevoluteJoint)_world.CreateJoint(jd);
}
Vector2 wheelAnchor;
wheelAnchor = pivot + new Vector2(0.0f, -0.8f);
CreateLeg(-1.0f, wheelAnchor);
CreateLeg(1.0f, wheelAnchor);
_wheel.SetTransform(_wheel.GetPosition(), 120.0f * (float)Settings.b2_pi / 180.0f);
CreateLeg(-1.0f, wheelAnchor);
CreateLeg(1.0f, wheelAnchor);
_wheel.SetTransform(_wheel.GetPosition(), -120.0f * (float)Settings.b2_pi / 180.0f);
CreateLeg(-1.0f, wheelAnchor);
CreateLeg(1.0f, wheelAnchor);
}
示例7: BodyTypes
public BodyTypes()
{
Body ground = null;
{
BodyDef bd = new BodyDef();
ground = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
shape.SetAsEdge(new Vector2(-20.0f, 0.0f), new Vector2(20.0f, 0.0f));
FixtureDef fd = new FixtureDef();
fd.shape = shape;
ground.CreateFixture(fd);
}
// Define attachment
{
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = new Vector2(0.0f, 3.0f);
_attachment = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
shape.SetAsBox(0.5f, 2.0f);
_attachment.CreateFixture(shape, 2.0f);
}
// Define platform
{
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = new Vector2(-4.0f, 5.0f);
_platform = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
shape.SetAsBox(0.5f, 4.0f, new Vector2(4.0f, 0.0f), 0.5f * (float)Math.PI);
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.friction = 0.6f;
fd.density = 2.0f;
_platform.CreateFixture(fd);
RevoluteJointDef rjd = new RevoluteJointDef();
rjd.Initialize(_attachment, _platform, new Vector2(0.0f, 5.0f));
rjd.maxMotorTorque = 50.0f;
rjd.enableMotor = true;
_world.CreateJoint(rjd);
PrismaticJointDef pjd = new PrismaticJointDef();
pjd.Initialize(ground, _platform, new Vector2(0.0f, 5.0f), new Vector2(1.0f, 0.0f));
pjd.maxMotorForce = 1000.0f;
pjd.enableMotor = true;
pjd.lowerTranslation = -10.0f;
pjd.upperTranslation = 10.0f;
pjd.enableLimit = true;
_world.CreateJoint(pjd);
_speed = 3.0f;
}
// Create a payload
{
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = new Vector2(0.0f, 8.0f);
Body body = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
shape.SetAsBox(0.75f, 0.75f);
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.friction = 0.6f;
fd.density = 2.0f;
body.CreateFixture(fd);
}
}
示例8: ApplyForce
public ApplyForce()
{
_world.Gravity = new Vector2(0.0f, 0.0f);
const float k_restitution = 0.4f;
Body ground;
{
BodyDef bd = new BodyDef();
bd.position = new Vector2(0.0f, 20.0f);
ground = _world.CreateBody(bd);
PolygonShape shape = new PolygonShape();
FixtureDef sd = new FixtureDef();
sd.shape = shape;
sd.density = 0.0f;
sd.restitution = k_restitution;
// Left vertical
shape.SetAsEdge(new Vector2(-20.0f, -20.0f), new Vector2(-20.0f, 20.0f));
ground.CreateFixture(sd);
// Right vertical
shape.SetAsEdge(new Vector2(20.0f, -20.0f), new Vector2(20.0f, 20.0f));
ground.CreateFixture(sd);
// Top horizontal
shape.SetAsEdge(new Vector2(-20.0f, 20.0f), new Vector2(20.0f, 20.0f));
ground.CreateFixture(sd);
// Bottom horizontal
shape.SetAsEdge(new Vector2(-20.0f, -20.0f), new Vector2(20.0f, -20.0f));
ground.CreateFixture(sd);
}
{
Transform xf1 = new Transform();
xf1.R.Set(0.3524f * (float)Settings.b2_pi);
xf1.Position = MathUtils.Multiply(ref xf1.R, new Vector2(1.0f, 0.0f));
Vector2[] vertices = new Vector2[3];
vertices[0] = MathUtils.Multiply(ref xf1, new Vector2(-1.0f, 0.0f));
vertices[1] = MathUtils.Multiply(ref xf1, new Vector2(1.0f, 0.0f));
vertices[2] = MathUtils.Multiply(ref xf1, new Vector2(0.0f, 0.5f));
PolygonShape poly1 = new PolygonShape();
poly1.Set(vertices, 3);
FixtureDef sd1 = new FixtureDef();
sd1.shape = poly1;
sd1.density = 4.0f;
Transform xf2 = new Transform();
xf2.R.Set(-0.3524f * (float)Settings.b2_pi);
xf2.Position = MathUtils.Multiply(ref xf2.R, new Vector2(-1.0f, 0.0f));
vertices[0] = MathUtils.Multiply(ref xf2, new Vector2(-1.0f, 0.0f));
vertices[1] = MathUtils.Multiply(ref xf2, new Vector2(1.0f, 0.0f));
vertices[2] = MathUtils.Multiply(ref xf2, new Vector2(0.0f, 0.5f));
PolygonShape poly2 = new PolygonShape();
poly2.Set(vertices, 3);
FixtureDef sd2 = new FixtureDef();
sd2.shape = poly2;
sd2.density = 2.0f;
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.angularDamping = 5.0f;
bd.linearDamping = 0.1f;
bd.position = new Vector2(0.0f, 2.0f);
bd.angle = (float)Settings.b2_pi;
bd.allowSleep = false;
_body = _world.CreateBody(bd);
_body.CreateFixture(sd1);
_body.CreateFixture(sd2);
}
{
PolygonShape shape = new PolygonShape();
shape.SetAsBox(0.5f, 0.5f);
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.3f;
for (int i = 0; i < 10; ++i)
{
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = new Vector2(0.0f, 5.0f + 1.54f * i);
Body body = _world.CreateBody(bd);
body.CreateFixture(fd);
//.........这里部分代码省略.........
示例9: LoadContent
/// <summary>
/// Call this to initialize a Behaviour with data supplied in a file.
/// </summary>
/// <param name="fileName">The file to load from.</param>
public override void LoadContent(String fileName)
{
base.LoadContent(fileName);
Int32[] input = { 1, 7, 2, 2, 3, /**/ 15, 16, 14, 16, 17 };
mMapData = new List<Int32>(input);
TileMapRenderDefinition def = GameObjectManager.pInstance.pContentManager.Load<TileMapRenderDefinition>(fileName);
mTexture = GameObjectManager.pInstance.pContentManager.Load<Texture2D>(def.mSpriteFileName);
mSourceWidth = 16;
mSourceHeight = 16;
mMapCountWidth = mTexture.Width / mSourceWidth;
mMapCountHeight = mTexture.Height / mSourceHeight;
var shape = new PolygonShape();
shape.SetAsBox(PhysicsManager.pInstance.ScreenToPhysicalWorld(mSourceWidth / 2 * 5),
PhysicsManager.pInstance.ScreenToPhysicalWorld(mSourceHeight / 2 * 2));
var fd = new FixtureDef();
fd.shape = shape;
fd.restitution = 0.0f;
fd.friction = 0.5f;
fd.density = 0.0f;
BodyDef bd = new BodyDef();
mGround = PhysicsManager.pInstance.pWorld.CreateBody(bd);
mGround.CreateFixture(fd);
shape.SetAsBox(PhysicsManager.pInstance.ScreenToPhysicalWorld(mSourceWidth / 2 * 5),
PhysicsManager.pInstance.ScreenToPhysicalWorld(mSourceHeight / 2 * 2),
PhysicsManager.pInstance.ScreenToPhysicalWorld(new Vector2(mSourceWidth * -5, 0.0f)),
0.0f);
fd = new FixtureDef();
fd.shape = shape;
fd.restitution = 0.0f;
fd.friction = 0.5f;
fd.density = 0.0f;
mGround.CreateFixture(fd);
}
示例10: LaunchBomb
public void LaunchBomb(Vector2 position, Vector2 velocity)
{
if (_bomb != null)
{
_world.DestroyBody(_bomb);
_bomb = null;
}
BodyDef bd = new BodyDef();
bd.type = BodyType.Dynamic;
bd.position = position;
bd.bullet = true;
_bomb = _world.CreateBody(bd);
_bomb.SetLinearVelocity(velocity);
CircleShape circle = new CircleShape();
circle._radius = 0.3f;
FixtureDef fd = new FixtureDef();
fd.shape = circle;
fd.density = 20.0f;
fd.restitution = 0.0f;
Vector2 minV = position - new Vector2(0.3f,0.3f);
Vector2 maxV = position + new Vector2(0.3f,0.3f);
AABB aabb;
aabb.lowerBound = minV;
aabb.upperBound = maxV;
_bomb.CreateFixture(fd);
}