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

发布于 2024-10-26 00:04:36 字数 104 浏览 8 评论 0原文

我在我的 XNA 项目中设置了 Farseer,并且有一个由于重力而不断下落的玩家身体。我希望玩家做的是使用“从图像创建形状”功能“着陆”在窗口中的随机边缘图像上。如何使玩家身体对象与形状碰撞?

I have setup Farseer in my XNA project and have a player body which falls endlessly because of gravity. What I want the player to do is "land" on the random edged image I have in the window using the create shape from image function. How do I make the player body object collide with the shape?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2024-11-02 00:04:36

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

   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);

此代码示例来自文档。我强烈建议下载演示并查看每个演示是如何用代码构建的。它会对你有很大帮助:-)

You shouldn't have to do anything explicitly ... just add the body into the same world and they will collide based on the properties you've given them (mass, shape, etc.).

   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);

This code sample is from the documentation. I highly suggest downloading the demos and seeing how each demo is constructed in code. it will greatly help you :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文