XNA& Farseer - 与随机边缘形状的碰撞

时间:2011-03-23 17:24:38

标签: c# xna 2d physics farseer

我在XNA项目中设置了Farseer,玩家身体因重力而无休止地下降。我希望玩家做的是使用图像功能的创建形状在窗口中的随机边缘图像上“着陆”。如何让玩家身体对象与形状碰撞?

1 个答案:

答案 0 :(得分:0)

你不应该明确地做任何事情......只需将身体添加到同一个世界中它们就会根据你给它们的属性(质量,形状等)发生碰撞。

   1:  //Create a World object with zero gravity
   2:  World world = new World(Vector2.Zero);
   3:              
   4:  //We create a body object and make it dynamic (movable)
   5:  Body myBody = world.CreateBody();
   6:  myBody.BodyType = BodyType.Dynamic;
   7:   
   8:  //We create a circle shape with a radius of 0.5 meters
   9:  CircleShape circleShape = new CircleShape(0.5f);
  10:   
  11:  //We fix the body and shape together using a Fixture object
  12:  Fixture fixture = myBody.CreateFixture(circleShape);

此代码示例来自documentation。我强烈建议下载演示并了解每个演示如何在代码中构建。它会对你有很大的帮助: - )