简体   繁体   English

开发跨平台XNA库

[英]Developing a Cross Platform XNA Library

I'm trying to develop a cross platform application. 我正在尝试开发跨平台应用程序。 Currently I have set up following solutions, with their platform specified template: 目前,我已经使用平台指定的模板设置了以下解决方案:

  • GameBase GameBase
  • Windows 视窗
  • Xbox 的Xbox
  • WindowsPhone WindowsPhone的

The Windows, Xbox and WindowsPhone uses the GameBase as reference, but I want to separate different code for each platform used in the GameBase library as the example below: Windows,Xbox和WindowsPhone使用GameBase作为参考,但是我想为GameBase库中使用的每个平台分别分配不同的代码,如下例所示:

#if WINDOWS

    graphics.PreferredBackBufferWidth = 640;
    graphics.PreferredBackBufferHeight = 480;
    graphics.ApplyChanges();

    #elif WINDOWS_PHONE

    TargetElapsedTime = TimeSpan.FromTicks(333333);
    InactiveSleepTime = TimeSpan.FromSeconds(1);

    #endif

It does not work, and I can see that in the Configuration Manager, that GameBase's platform is Any CPU, so I wonder if it has anything to due with the GameBase being a Class Library? 它不起作用,我可以在配置管理器中看到GameBase的平台是Any CPU,所以我想知道GameBase是类库吗?

If so how do I fix it, and if possible I would like to keep the #if tags. 如果是这样,我该如何解决它,如果可能的话,我想保留#if标签。

Directory setup | 目录设置| Windows Solution Game.cs | Windows解决方案Game.cs | Solution Explorer 解决方案资源管理器 目录设置| Windows解决方案Game.cs |解决方案资源管理器

You have to create separate Visual Studio projects for the different platforms. 您必须为不同的平台创建单独的Visual Studio项目。 You can reuse code across multiple projects by adding the source using Add As Link . 通过使用“ 添加为链接”添加源代码,可以跨多个项目重用代码。 Within a shared source file that is linked to multiple project you can use #if etc. to separate platform specific code. 在链接到多个项目的共享源文件中,您可以使用#if等分隔平台特定的代码。

添加为链接截图

How "It does not work" is not clear from your question but in general you cannot build an assembly (eg class library) for Windows and then use it on XBox and Windows Phone. 您的问题尚不清楚“它不起作用”的方式,但是通常您无法为Windows构建程序集(例如类库),然后在XBox和Windows Phone上使用它。

Sharing projects between different project types is a tricky thing to do - just because of the way Visual Studio project types are used and because the different project types actually need to reference different versions of the dot net framework. 在不同项目类型之间共享项目是一件棘手的事情-仅仅是因为Visual Studio项目类型的使用方式,而且由于不同的项目类型实际上需要引用点网框架的不同版本。

There are a few things that can assist: 有几件事可以帮助您:

Hope that helps a bit. 希望有点帮助。 Personally I'm currently mainly using manual cut and paste and hoping that the next version of the Portable Class Library helps (it is due for Win8 Metro stuff) 我个人目前主要使用手动剪切和粘贴,希望便携式版本库的下一个版本有所帮助(这是Win8 Metro的东西)

Not sure if this is your only problem but you mispelled WINDOWS_PHONE: 不知道这是否是您唯一的问题,但您拼错了WINDOWS_PHONE:

WINDOWS_HPONE

should be: 应该:

WINDOWS_PHONE

UPDATE: 更新:

The way that I would do it is I would create a class library solution calling it something like GameBaseLibrary. 我这样做的方法是创建一个类库解决方案,将其命名为GameBaseLibrary。 Then create a project there called GameBase and add all code in there that you would like to share across all the platforms. 然后在其中创建一个名为GameBase的项目,并在其中添加您要在所有平台上共享的所有代码。 (IE Physics, data access, etc...) (IE物理,数据访问等...)

Then in that same solution add XboxBaseLibrary, WindowsBaseLibrary, WindowsPhoneBaseLibrary and add code which is specific to each platform, add a reference in each of those projects to the GameBase project to use code from there in each of the three other projects. 然后,在同一解决方案中,添加XboxBaseLibrary,WindowsBaseLibrary,WindowsPhoneBaseLibrary并添加特定于每个平台的代码,在每个项目中向GameBase项目添加一个引用,以使用其他三个项目中的代码。

Then create 3 different solutions types - Xbox, Window, Windows Phone and add the compiled dlls from GameBaseLibrary as a reference in each of them to be able to use the code. 然后创建3种不同的解决方案类型-Xbox,Window,Windows Phone,并从GameBaseLibrary中添加已编译的dll作为它们各自的引用,以便能够使用该代码。 As you're working on each version of code (xbox, windows, windows phone) pay attention to code that you're typing to ensure that it's not something which can live within the GameBase class because you don't want to keep rewriting the same code. 在处理每个版本的代码(xbox,Windows,Windows Phone)时,请注意所键入的代码,以确保它不会存在于GameBase类中,因为您不想继续重写相同的代码。

This way, the bulk of the code is sitting in GameBaseLibrary and the platform specific code is sitting within each of the 3 other projects. 这样,大部分代码位于GameBaseLibrary中,而平台特定代码位于其他3个项目中。

I hope this is clear. 我希望这很清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正在开发Mono跨平台? - Is developing in Mono cross-platform? 跨平台 Nuget 库 - Cross Platform Nuget Library 在Apple上开发(新平台) - Developing on Apple (new platform) 使用 C# 的 Mac 和 Windows 跨平台类库 - Cross platform class library for Mac and Windows using C# 使用包含点的库在跨平台(ubuntu / windows)上调用p / invoke - Calling p/invoke on cross platform (ubuntu/windows) with library that contains dots 如何在Visual Studio跨平台android项目中引用.so库? - How to reference .so library in visual studio cross platform android project? 哪些项目需要在跨平台解决方案中引用.Net标准库 - What projects need to reference the .Net Standard Library in a Cross Platform Solution 使用Xamarin开发跨平台应用程序时使用C#从Azure存储帐户表中检索记录,并给出错误 - Retrieving records from Azure Storage account table using c# while developing cross platform app using xamarin giving error 我正在开发一个简单的跨平台系统任务栏应用程序。 这里是要求,我应该使用哪些工具? - I'm developing a simple cross platform system tray application. Here are the requirements, which tools should I use? XNA的UI库 - UI library for XNA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM