本文整理汇总了C#中FarseerPhysics.Dynamics.Body.CreateFixture方法的典型用法代码示例。如果您正苦于以下问题:C# Body.CreateFixture方法的具体用法?C# Body.CreateFixture怎么用?C# Body.CreateFixture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Dynamics.Body
的用法示例。
在下文中一共展示了Body.CreateFixture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadContent
public void LoadContent(ContentManager content, World world, Vector2 position, Vector2 size)
{
body = BodyFactory.CreateRectangle(world, size.X, size.Y, 1f);
body.FixedRotation = true;
body.FixtureList[0].UserData = 9000;
body.Position = ConvertUnits.ToSimUnits(position);
body.BodyType = BodyType.Dynamic;
CircleShape circle1 = new CircleShape(size.X / 4, 1f);
CircleShape circle2 = new CircleShape(size.Y / 6, 1f);
CircleShape circle3 = new CircleShape(size.Y / 6, 1f);
circle1.Position = new Vector2(0, -size.Y / 3);
circle2.Position = new Vector2(-1.5f * size.X / 5, -size.Y / 10);
circle3.Position = new Vector2(-0.4f * size.X / 5, -size.Y / 10);
head = body.CreateFixture(circle1);
hands[0] = body.CreateFixture(circle2);
hands[1] = body.CreateFixture(circle3);
head.UserData = (int)10000;
hands[0].UserData = (int)11000;
hands[1].UserData = (int)11000;
image.LoadContent(content, "Graphics/tezka", Color.White, position);
image.ScaleToMeters(size);
image.position = ConvertUnits.ToDisplayUnits(body.Position);
}
示例2: ConvertPathToEdges
//Contributed by Matthew Bettcher
/// <summary>
/// Convert a path into a set of edges and attaches them to the specified body.
/// Note: use only for static edges.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="subdivisions">The subdivisions.</param>
public static void ConvertPathToEdges(Path path, Body body, int subdivisions)
{
List<Vector2> verts = path.GetVertices(subdivisions);
for (int i = 1; i < verts.Count; i++)
{
body.CreateFixture(new PolygonShape(PolygonTools.CreateEdge(verts[i], verts[i - 1]), 0));
}
if (path.Closed)
{
body.CreateFixture(new PolygonShape(PolygonTools.CreateEdge(verts[verts.Count - 1], verts[0]), 0));
}
}
示例3: CreateBounds
private static void CreateBounds(float width, float height)
{
var body = new Body(world);
body.BodyType = BodyType.Static;
var bottom = new PolygonShape(PolygonTools.CreateRectangle(width / 2, 0.1f, new Vector2(width / 2, height), 0), 5);
var top = new PolygonShape(PolygonTools.CreateRectangle(width / 2, 0.1f, new Vector2(width / 2, 0), 0), 5);
var left = new PolygonShape(PolygonTools.CreateRectangle(0.1f, height / 2, new Vector2(0, height / 2), 0), 5);
var right = new PolygonShape(PolygonTools.CreateRectangle(0.1f, height / 2, new Vector2(width, height / 2), 0), 5);
body.CreateFixture(bottom);
body.CreateFixture(top);
body.CreateFixture(left);
body.CreateFixture(right);
}
示例4: Zombie
public Zombie(Rectangle pos, Map m)
: base(m)
{
Body BodyDec = new Body(m.PhysicalWorld);
BodyDec.BodyType = BodyType.Dynamic;
Fixture = BodyDec.CreateFixture(new CircleShape(15f, 2.5f));
//Fixture.Restitution = 0f;
walkAnim = new Animation();
walkNormalAnim = new AnimationNormal();
walkAnim.Load("ZombieAnim", Vector2.One * 64, 6, 200);
walkNormalAnim.Load("ZombieAnim_normal", Vector2.One * 64, 6, 200, (LightingEngine)Renderer.GetRenderEffect("LightingEngine"));
walkAnim.Center = Vector2.One * 32;
walkNormalAnim.Center = Vector2.One * 32;
Position = pos;
hp = 100;
def = 1;
damage = 2;
lucky = 1;
SetName("zombie");
sounds = new Dictionary<string, ISound>();
//sounds.Add("Sounds/Mobs/zombie_walk", GeneralManager.Sounds["Sounds/Mobs/zombie_walk"].CreateInstance());
//sounds.Add("zombie_moan", GeneralManager.Sounds["Sounds/Mobs/zombie_moan"].CreateInstance());
//pfinder = new PathFinderFast(m.GetChunk().GetCostArray());
}
示例5: Ship
public Ship(World world, SpawnData spawn, int id)
{
Ball = null;
Id = id;
IsThrusting = false;
IsReversing = false;
IsBoosting = false;
IsLeftTurning = false;
IsRightTurning = false;
IsShooting = false;
IsBlocked = false;
IsBlockedFrame = false;
Color = spawn.Color;
var body = new Body(world);
body.Rotation = FMath.Atan2(-spawn.Position.Y, -spawn.Position.X);
body.Position = spawn.Position;
var shape = new CircleShape(radius, 1f);
body.BodyType = BodyType.Dynamic;
body.FixedRotation = true;
Fixture = body.CreateFixture(shape);
Fixture.Restitution = restitution;
var bodyGravity = new Body(world);
bodyGravity.Position = spawn.Position;
var shapeGravity = new CircleShape(radiusGravity, 1f);
bodyGravity.FixedRotation = true;
FixtureGravity = bodyGravity.CreateFixture(shapeGravity);
FixtureGravity.IsSensor = true;
}
示例6: Missile
public Missile(
ISoundManager soundManager,
World world,
Collection<IDoodad> doodads,
int numberOfBounces,
Team team,
Vector2 position,
float rotation,
DoodadFactory doodadFactory)
{
this.soundManager = soundManager;
this.doodadFactory = doodadFactory;
this.world = world;
this.doodads = doodads;
this.numberOfBounces = numberOfBounces;
this.body = BodyFactory.CreateBody(world, position, this);
this.body.BodyType = BodyType.Dynamic;
this.body.FixedRotation = true;
CircleShape shape = new CircleShape(5 / Constants.PixelsPerMeter, 0.1f);
Fixture fixture = body.CreateFixture(shape);
fixture.Restitution = 1;
fixture.Friction = 0;
fixture.CollisionCategories = PhysicsConstants.MissileCategory;
fixture.CollidesWith = PhysicsConstants.EnemyCategory | PhysicsConstants.PlayerCategory |
PhysicsConstants.ObstacleCategory | PhysicsConstants.MissileCategory |
PhysicsConstants.SensorCategory;
obstacleCollisionCtr = 0;
Vector2 force = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * 3;
this.body.ApplyForce(force);
}
示例7: Bullet
protected Bullet(Ship parent, Vector2 offset, Vector2 speed, string texture)
: base(parent, texture, parent.Size)
{
Sprite.Origin = new Vector2f(Sprite.Texture.Size.X / 2f, 0);
#region Body Initialize
Body = new Body(State.World);
Body.BodyType = BodyType.Dynamic;
Body.IsBullet = true;
var shape = new CircleShape((0.15f / 4) * parent.Size, 0);
Body.CreateFixture(shape);
Body.Position = parent.Body.Position + parent.Body.GetWorldVector(offset);
Body.Rotation = parent.Body.Rotation;
Body.OnCollision += (a, b, contact) =>
{
if (!Collision(a, b, contact))
return false;
Dead = true;
return false;
};
Body.LinearVelocity = Parent.Body.LinearVelocity + Parent.Body.GetWorldVector(speed);
Body.UserData = this;
#endregion
}
示例8: Asteroid
public Asteroid(State state, Vector2 position, int? typeOverride = null, bool isStatic = false)
: base(state)
{
var type = typeOverride.HasValue ? typeOverride.Value : Program.Random.Next(Radiuses.Count);
var radius = Radiuses[type];
_sprite = new Sprite(Assets.LoadTexture(string.Format("asteroid{0}.png", type))).Center();
var c = (byte)Program.Random.Next(180, 255);
_sprite.Color = new Color(c, c, c);
#region Body Initialize
Body = new Body(State.World);
Body.BodyType = BodyType.Dynamic;
Body.LinearDamping = 0.5f;
Body.AngularDamping = 0.5f;
var shape = new FarseerPhysics.Collision.Shapes.CircleShape(radius, 20 * radius);
Body.CreateFixture(shape);
Body.UserData = this;
if (isStatic)
Body.BodyType = BodyType.Static;
Body.Position = position;
Body.Rotation = (float)(Program.Random.NextDouble() * (Math.PI * 2));
#endregion
}
示例9: Key
public Key(Rectangle pos, Map map)
: base(map)
{
Body BodyDec = new Body(map.PhysicalWorld);
BodyDec.BodyType = BodyType.Static;
PolygonShape S = new PolygonShape(1f);
S.SetAsBox(pos.Width / 2, pos.Height / 2);
Fixture = BodyDec.CreateFixture(S);
Fixture.Restitution = 1f;
Fixture.Friction = 10f;
this.Position = pos;
SetName("Key");
LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");
light = new PointLight()
{
IsEnabled = true,
Color = new Vector4(0.95f, .7f, .05f, 1f),
Power = power,
LightDecay = 350,
Position = new Vector3(Position.X, Position.Y, 20),
Direction = new Vector3(0,0, 0)
};
LE.AddLight(light);
}
示例10: CreateBullets
private static void CreateBullets(Body ship)
{
Func<Vector2, Body> createBullet = pos =>
{
var body = new Body(world);
body.BodyType = BodyType.Dynamic;
body.IsBullet = true;
var shape = new FarseerCircleShape(0.15f / 4, 1);
body.CreateFixture(shape);
body.Position = ship.Position + ship.GetWorldVector(pos);
body.Rotation = ship.Rotation;
body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -15f)));
body.OnCollision += (a, b, contact) =>
{
world.RemoveBody(body);
return false;
};
return body;
};
createBullet(new Vector2(-0.575f, -0.20f));
createBullet(new Vector2(0.575f, -0.20f));
}
示例11: Chest
public Chest(Rectangle r,Map m)
: base(m)
{
Body BodyDec = new Body(m.PhysicalWorld);
BodyDec.BodyType = BodyType.Static;
PolygonShape S = new PolygonShape(1f);
S.SetAsBox(r.Width / 2, r.Height / 2);
Fixture = BodyDec.CreateFixture(S);
Fixture.Restitution = 1f;
Fixture.Friction = 10f;
Position = r;
SetName("Chest");
items = new List<Item>();
ChestWindow = new Window(GeneralManager.GetPartialRect(0.4f, 0.2f, 0.2f, 0.6f));
ChestWindow.BgTex = GeneralManager.Textures["GUI/InGameGUI/ChestMenuBg"];
ChestWindow.Visible = false;
CloseButton = new Button(new Rectangle(ChestWindow.Position.Width - 32, 8, 24, 24), "", GeneralManager.Textures["GUI/InGameGUI/CloseButton"], Color.Gray, Color.White, null);
CloseButton.Action = CloseChestWindow;
ChestWindow.AddGUI(CloseButton );
list = new ListBox(new Rectangle(16,16,ChestWindow.Position.Width - 24,ChestWindow.Position.Height - 32));
ChestWindow.AddGUI(list);
Map.Parent.AddGUI(ChestWindow);
}
示例12: Goalie
public Goalie(World world, GoalieData spawn)
{
var body = new Body(world);
var angle = spawn.End - spawn.Begin;
body.Rotation = FMath.Atan2(angle.Y, angle.X);
segment.A = spawn.Begin;
segment.B = spawn.End;
var normal = new Vector2(-angle.Y, angle.X);
normal.Normalize();
delta = normal * .5f;
segmentOut.A = spawn.Begin + delta;
segmentOut.B = spawn.End + delta;
segmentIn.A = spawn.Begin - delta;
segmentIn.B = spawn.End - delta;
body.Position = spawn.Begin;
var verts = new Vertices();
verts.Add(new Vector2(left, bottom));
verts.Add(new Vector2(right, bottom));
verts.Add(new Vector2(right, top));
verts.Add(new Vector2(left, top));
var shape = new PolygonShape(verts, 1f);
body.FixedRotation = true;
body.BodyType = BodyType.Dynamic;
Fixture = body.CreateFixture(shape);
}
示例13: CoolRibbonObject
public CoolRibbonObject(World world, Texture2D tex)
{
points = new List<Vector2>();
points.Add(new Vector2(4, -1));
points.Add(new Vector2(4, 22));
points.Add(new Vector2(30, 22));
points.Add(new Vector2(30, -1));
stops = new float[4];
for(int i = 0; i < points.Count-1; i++)
{
stops[i] = Vector2.Distance(points[i],points[i+1]);
}
body = BodyFactory.CreateBody(world);
body.BodyType = BodyType.Static;
body.Position = new Vector2(0,0);
body.UserData = this;
hinges = new List<Hinge>();
AddBox(world, tex);
ChainShape chain = new ChainShape(new Vertices(points));
fixture = body.CreateFixture(chain);
}
示例14: NetworkCollisionRemnant
public NetworkCollisionRemnant(Vector2 position, float size, float angleOfStartForce, int ownerId, Color color, World world, Player creator)
: base(position, size, color, null, creator)
{
OwnerId = ownerId;
body = BodyFactory.CreateBody(world);
body.BodyType = BodyType.Dynamic;
body.Position = ConvertUnits.ToSimUnits(position);
body.FixedRotation = true;
body.LinearDamping = 0.8f;
//Create the vertices that will create the collision shape
Vertices verts = new Vertices();
verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f)));
//Create the shape and attach it to the body
PolygonShape s = new PolygonShape(verts, 0);
body.CreateFixture(s);
body.FixtureList[0].IsSensor = true;
body.UserData = this;
body.CollidesWith = Category.Cat2;
body.CollisionCategories = Category.Cat2;
//body.OnSeparation += body_OnSeparation;
body.ApplyLinearImpulse(new Vector2((float)Math.Cos(angleOfStartForce),(float)Math.Sin(angleOfStartForce)) * 10f);
}
示例15: RopeTest
private RopeTest()
{
Body ground;
{
ground = new Body(World);
EdgeShape shape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(shape);
}
{
Body prevBody = ground;
PolygonShape largeShape = new PolygonShape(PolygonTools.CreateRectangle(1.5f, 1.5f), 100);
PolygonShape smallShape = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.125f), 20);
const int N = 10;
const float y = 15;
for (int i = 0; i < N; ++i)
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.5f + 1.0f * i, y);
if (i == N - 1)
{
Fixture fixture = body.CreateFixture(largeShape);
fixture.Friction = 0.2f;
fixture.CollisionCategories = Category.Cat2;
fixture.CollidesWith = Category.All & ~Category.Cat2;
body.Position = new Vector2(1.0f * i, y);
body.AngularDamping = 0.4f;
}
else
{
Fixture fixture = body.CreateFixture(smallShape);
fixture.Friction = 0.2f;
fixture.CollisionCategories = Category.Cat1;
fixture.CollidesWith = Category.All & ~Category.Cat2;
}
Vector2 anchor = new Vector2(i, y);
RevoluteJoint jd = new RevoluteJoint(prevBody, body, prevBody.GetLocalPoint(ref anchor),
body.GetLocalPoint(ref anchor));
jd.CollideConnected = false;
World.AddJoint(jd);
prevBody = body;
}
_rj = new RopeJoint(ground, prevBody, new Vector2(0, y), Vector2.Zero);
//FPE: The two following lines are actually not needed as FPE sets the MaxLength to a default value
const float extraLength = 0.01f;
_rj.MaxLength = N - 1.0f + extraLength;
World.AddJoint(_rj);
}
}