本文整理汇总了C#中FarseerPhysics.Dynamics.World.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# World.Clear方法的具体用法?C# World.Clear怎么用?C# World.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Dynamics.World
的用法示例。
在下文中一共展示了World.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
public void Deserialize(World world, Stream stream)
{
world.Clear();
XMLFragmentElement root = XMLFragmentParser.LoadFromStream(stream);
if (root.Name.ToLower() != "world")
throw new Exception();
foreach (XMLFragmentElement main in root.Elements)
{
if (main.Name.ToLower() == "gravity")
{
world.Gravity = ReadVector(main);
}
}
foreach (XMLFragmentElement shapeElement in root.Elements)
{
if (shapeElement.Name.ToLower() == "shapes")
{
foreach (XMLFragmentElement n in shapeElement.Elements)
{
if (n.Name.ToLower() != "shape")
throw new Exception();
ShapeType type = (ShapeType)Enum.Parse(typeof(ShapeType), n.Attributes[0].Value, true);
switch (type)
{
case ShapeType.Circle:
{
CircleShape shape = new CircleShape();
foreach (XMLFragmentElement sn in n.Elements)
{
switch (sn.Name.ToLower())
{
case "radius":
shape.Radius = float.Parse(sn.Value);
break;
case "position":
shape.Position = ReadVector(sn);
break;
default:
throw new Exception();
}
}
_shapes.Add(shape);
}
break;
case ShapeType.Polygon:
{
PolygonShape shape = new PolygonShape();
foreach (XMLFragmentElement sn in n.Elements)
{
switch (sn.Name.ToLower())
{
case "vertices":
{
List<Vector2> verts = new List<Vector2>();
foreach (XMLFragmentElement vert in sn.Elements)
verts.Add(ReadVector(vert));
shape.Set(new Vertices(verts.ToArray()));
}
break;
case "centroid":
shape.MassData.Centroid = ReadVector(sn);
break;
}
}
_shapes.Add(shape);
}
break;
case ShapeType.Edge:
{
EdgeShape shape = new EdgeShape();
foreach (XMLFragmentElement sn in n.Elements)
{
switch (sn.Name.ToLower())
{
case "hasvertex0":
shape.HasVertex0 = bool.Parse(sn.Value);
break;
case "hasvertex3":
shape.HasVertex0 = bool.Parse(sn.Value);
break;
case "vertex0":
shape.Vertex0 = ReadVector(sn);
break;
case "vertex1":
shape.Vertex1 = ReadVector(sn);
break;
case "vertex2":
shape.Vertex2 = ReadVector(sn);
//.........这里部分代码省略.........
示例2: Initialize
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
mines = new List<Mine>();
explosions = new List<Explosion>();
weaponCharges = new List<IPowerup>();
bombs = new List<Bomb>();
world = new World(new Vector2(0.0f, -20f));
PrimitiveDrawing.SetUp(this.world);
//FarseerPhysics.Settings.EnableDiagnostics = false;
FarseerPhysics.Settings.MaxPolygonVertices = 30;
highScore = 20; //TODO
world.Clear();
shielded = false;
botherBall = null;
speedTimer = 0;
timeSinceStart = 0;
touchedGround = true;
score = 0;
ball = BodyFactory.CreateCircle(world, 1.5f, 1f, new Vector2(0.0f, 3f), ballColor);
ball.BodyType = BodyType.Dynamic;
ball.Friction = 10;
floorBody = new Body(world)
{
BodyType = BodyType.Static,
Position = Vector2.Zero,
FixedRotation = true
};
currentFloorLength = 0;
BodyFactory.CreateRectangle(world, 4f, (float)(1706665.0 / 512.0), 1f, new Vector2(-35.4333f, ball.Position.Y), Color.Black).Friction = 0.0f;
BodyFactory.CreateRectangle(world, 4f, (float)(1706665.0 / 512.0), 1f, new Vector2(35.3333f, ball.Position.Y), Color.Black).Friction = 0.0f;
highScoreLine = BodyFactory.CreateRectangle(
world,
66.6666f,
(float)(66.6666030883789 / (double)this.GraphicsDevice.Viewport.AspectRatio / 40.0),
1f,
new Vector2(0.0f, (float)(-this.highScore - 66.6666030883789 / (double)this.GraphicsDevice.Viewport.AspectRatio / 80.0)),
Color.Red
);
highScoreLine.IsStatic = true;
highScoreLine.IsSensor = true;
ball.OnCollision += Ball_OnCollision;
world.Step(1000);
base.Initialize();
}
示例3: Generate
public Level Generate(World world)
{
world.Clear();
return new Level();
}
示例4: Deserialize
public void Deserialize(World world, Stream stream)
{
world.Clear();
_namedBodies.Clear();
_namedFixtures.Clear();
string content;
using (var reader = new StreamReader(stream))
content = RemoveComments(reader.ReadToEnd());
var jsonWorld = JObject.Parse(content);
foreach (JProperty worldProperty in jsonWorld.Children())
{
//World properties
switch (worldProperty.Name)
{
case "gravity":
world.Gravity = ParseVector2(worldProperty);
break;
//case "allowSleep":
// break;
case "autoClearForces":
world.AutoClearForces = (bool) worldProperty.Value;
break;
//case "positionIterations":
// break;
//case "velocityIterations":
// break;
//case "stepsPerSecond":
// break;
//case "warmStarting":
// break;
//case "continuousPhysics":
// break;
case "subStepping":
world.EnableSubStepping = (bool)worldProperty.Value;
break;
case "body":
break; //ignore
default:
System.Diagnostics.Debug.WriteLine(worldProperty.Name + " not supported");
break;
}
}
var bodies = (JArray)jsonWorld["body"];
var images = (JArray)jsonWorld["image"];
var joints = (JArray)jsonWorld["joint"];
if (bodies != null)
{
foreach (JObject jsonBody in bodies)
ParseBody(jsonBody, world);
}
if (images != null)
{
throw new NotImplementedException();
}
if (joints != null)
{
throw new NotImplementedException();
}
}