本文整理汇总了C#中Body.Duplicate方法的典型用法代码示例。如果您正苦于以下问题:C# Body.Duplicate方法的具体用法?C# Body.Duplicate怎么用?C# Body.Duplicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body.Duplicate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Open
protected override void Open()
{
dispose += DemoHelper.BasicDemoSetup(DemoInfo);
IShape fighterShape = ShapeFactory.CreateSprite(Cache<SurfacePolygons>.GetItem("fighter.png"), 4, 50, 5);
Body fighter = new Body(new PhysicsState(new ALVector2D(0, 300, 300)), fighterShape, 5000, new Coefficients(0, 1), new Lifespan());
fighter.State.Velocity.Angular = 9;
fighter.Mass.MomentOfInertia = Scalar.PositiveInfinity;
BodyGraphic fighterGraphic = new BodyGraphic(fighter);
Scene.AddGraphic(fighterGraphic);
BodyGraphic fighterGraphic2 = (BodyGraphic)fighterGraphic.Duplicate();
fighterGraphic2.Body.State.Position.Linear.Y = 500;
fighterGraphic2.Body.State.Velocity.Angular = -8.5f;
Scene.AddGraphic(fighterGraphic2);
Body template2 = new Body(new PhysicsState(new ALVector2D(0, 200, 200)), ParticleShape.Default, 4, new Coefficients(0, 1), new Lifespan());
Matrix2x3 m = Matrix2x3.FromRotationZ(2);
int count = 0;
for (int x = -0; x < 1000; x += 25)
{
for (int y = -0; y < 1000; y += 25)
{
count++;
Body body = template2.Duplicate();
body.State.Position.Linear = new AdvanceMath.Vector2D(x, y);
body.ApplyPosition();
body.State.Velocity.Linear.X = (250 - x) / 10f;
body.State.Velocity.Linear.Y = (250 - y) / 10f;
body.State.Velocity.Linear = m * body.State.Velocity.Linear;
body.LinearDamping = .9999f;
BodyGraphic g1 = new BodyGraphic(body);
Scene.AddGraphic(g1);
}
}
Scene.Engine.AddLogic(new GravityPointField(new Vector2D(400, 400), 500, new Lifespan()));
}
示例2: RegisterMaintainSpawning
public static DisposeCallback RegisterMaintainSpawning(DemoOpenInfo info, Key key, Body body)
{
return RegisterMaintainSpawning(info, key,
delegate(Vector2D position)
{
Body dub = body.Duplicate();
dub.State.Position.Linear = position;
dub.ApplyPosition();
info.Scene.AddGraphic(CreateGraphic(dub));
return dub;
});
}
示例3: RegisterBodyStreamSpawning
public static DisposeCallback RegisterBodyStreamSpawning(
DemoOpenInfo info, Body body, int count,
Scalar minVelocity, Scalar maxVelocity, Key key)
{
bool isSpawning = false;
Scalar range = maxVelocity - minVelocity;
EventHandler<KeyboardEventArgs> downHandler = delegate(object sender, KeyboardEventArgs e)
{
if (e.Key == key)
{
isSpawning = true;
}
};
EventHandler<KeyboardEventArgs> upHandler = delegate(object sender, KeyboardEventArgs e)
{
if (e.Key == key)
{
isSpawning = false;
}
};
EventHandler<UpdatedEventArgs> updatedHandler = delegate(object sender, UpdatedEventArgs e)
{
if (!isSpawning) { return; }
Vector2D position = info.Viewport.MousePosition;
if (count == 1)
{
Body dub = body.Duplicate();
Vector2D velocityDirection = Vector2D.FromLengthAndAngle(1, NextScalar() * MathHelper.Pi);
dub.State.Position.Linear = position + velocityDirection;
dub.ApplyPosition();
dub.State.Velocity.Linear = velocityDirection * (minVelocity + NextScalar() * range);
info.Scene.AddGraphic(CreateGraphic(dub));
}
else
{
Graphic[] graphics = new Graphic[count];
for (int index = 0; index < count; ++index)
{
Body dub = body.Duplicate();
Vector2D velocityDirection = Vector2D.FromLengthAndAngle(1, NextScalar() * MathHelper.TwoPi);
dub.State.Position.Linear = position + velocityDirection;
dub.ApplyPosition();
dub.State.Velocity.Linear = velocityDirection * (minVelocity + NextScalar() * range);
graphics[index] = CreateGraphic(dub);
}
info.Scene.AddGraphicRange(graphics);
}
};
info.Scene.Engine.Updated += updatedHandler;
Events.KeyboardDown += downHandler;
Events.KeyboardUp += upHandler;
return delegate()
{
info.Scene.Engine.Updated -= updatedHandler;
Events.KeyboardDown -= downHandler;
Events.KeyboardUp -= upHandler;
};
}