将物理添加到 UWP 应用

Adding physics to a UWP app

目前我正在使用 Win2d 绘制所有元素。我已经阅读了关于 Win2d here:

Win2D is a graphics API rather than a complete all-in-one game engine, but you could certainly use it to implement the graphics portion of a 2D game, in combination with other APIs for other areas such as input, sound, physics if your game needs that, etc.

我研究了 Box2d(这是首选,因为我们的 Android 应用正在使用 Box2d)。但是当我使用 Nuget 安装 Box2d 时,我得到 Package restore failed. Rolling back to package changes for ...

我也在 Box2d 的网站上看到有一个名为 Farseer Physics Engine 的端口。我遇到了与 Box2d 相同的问题。

然后环顾四周,我发现了 Physics Helper XAML 和 运行 代码。这非常接近我们想要的,但在现有应用程序中设置它似乎很神秘。这使用了 Farseer Physics,它在模拟器中运行得很好。

我主要开发 Mac 和 Android 应用程序,所以我是新领域 运行 Visual Studio 并且在 windows 环境中开发。还有很多文档似乎已经过时了。

基本上我想知道什么是将物理添加到我的 UWP 的最佳方法,如果我还没有介绍另一种解决方案,我应该在这里探索,我很乐意听到它。

Farseer Physics Engine is not available for UWP Project. But Physics Helper XAML已经修改了源代码,使其可用于UWP App。因此,将 Physics 添加到您的 UWP 应用程序中的最快和最简单的方法是将 Physics Helper XAML 中的 Farseer Physics 的源代码添加到您的项目中。

您可以通过以下步骤实现:

  1. 在 VS->File->New->Project->Templates->Visual C#->Windows->Universal->Blank App(Universal Windows ).
  2. 将 FarseerPhysics 项目复制到您的 UWP 项目文件夹中。重定向到 Physics Helper XAML 的根文件夹,将 FarseerPhysics 文件夹复制到新创建的 UWP 项目的根文件夹中。
  3. 将复制的 FarseerPhysics 项目添加到您的 UWP 项目中。右键单击解决方案->添加->现有项目->您复制的 FarseerPhysics 文件夹->FarseerPhysics.csproj.
  4. 将 FarseerPhysics 引用到您的 UWP 项目中。在解决方案资源管理器中右键单击 UWP 项目的引用->添加引用->项目->解决方案->FarseerPhysics。

现在您可以在 UWP 项目中使用 FarseerPhysics。如果需要,您可以使用相同的步骤在 Physics Helper XAML 中添加对 PhysicsHelper 的引用。

下面是我制作的基本空 UWP 物理应用程序:EmptyUWPWithFarseer