Cocos2d 针对 iPhone/iPad/Mac
我最近做了一些关于为 iPhone/iPad 和 Mac 制作 cocos2d 应用程序的研究。我已经完成了 iPhone/iPad 路线,但从未在 Mac 目标上完成过。似乎有些人已将其添加为目标,但提到它很挑剔,而其他人则建议创建一个使用相同文件的单独的 Cocos2d Mac 项目。这里有什么智慧可以传授吗?
I recently did some research on making a cocos2d app for iPhone/iPad AND Mac. I have done the iPhone/iPad route but have never done it with a Mac target. It appears that some people have added it as a target but mentioned that it is finicky and others have suggested making a separate Cocos2d Mac project that uses the same files. Any wisdom to impart here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信在同一个项目中同时拥有 iOS 和 Mac 目标绝对至关重要。否则,您将花费太多时间保持一个平台与另一个平台同步,直到最终您要么设法创建一个良好的(但仍然耗时)工作流程,要么最终忽略两个平台之一。
理想情况下,代码库应尽可能少地使用编译器宏。您需要编译 iOS 和 Mac 代码,即使它不用于某一平台。因此,将一些类或方法
#ifdef
添加到 Mac,将其他类或方法添加到 iOS,在切换目标时通常会导致编译错误。这意味着包装类是必不可少的,这样无论平台如何,您都可以编写相同的代码。目前,Cocos2D 不提供您创建 iOS 和 Android 的功能。 Mac 目标位于同一 Xcode 项目中。实现这一目标的方法也不是显而易见的,因为每个目标都需要自己的构建设置:基础 SDK、SDK 根、部署目标、架构以及可能的编译器版本。如果您还想使用第 3 方库(Box2D、Chipmunk 等),情况会变得更糟,因为在某些情况下,您将被迫为这些库创建 iOS 和 Mac 特定目标 - 如果只是为了确保构建库的话使用与项目目标相同的编译器,否则您可能会遇到最奇怪的构建或运行时问题。
我在使这些特定于平台的目标在单个 Xcode 项目中工作而 Xcode 没有抱怨或出现其他异常行为时遇到了问题。我还没有在 Xcode 4.1 和 4.2 上尝试过。那时我已经创建了 .xcconfig 文件来托管构建设置。 .xcconfig 文件对于更新的 Xcode 版本可能是必需的,也可能不是必需的,但它们确实使管理多个特定于平台的目标变得更容易。
长话短说,使用 cocos2d-iphone 进行跨平台开发的最佳且最简单的方法是使用 Kobold2D。
15 个模板项目中的大多数每个项目都有 iOS 和 Mac 目标,您只需选择相应的方案,然后点击 build & 即可。跑步。最常用的特定于平台的代码(处理用户输入)被包装在与平台无关、易于使用的包装类中 KKInput。
免责声明:我是 Kobold2D 的开发者。我可能有偏见的可能性很小。无论如何,你应该尝试Kobold2D。 :)
I believe it is absolutely crucial to have both iOS and Mac targets in the same project. Otherwise you'll spend too much time keeping one platform in synch with the other, until eventually you either manage to create a good (but still time-consuming) workflow - or end up neglecting one of the two platforms.
Ideally the code base should make as little use as possible of compiler macros. You'll want to compile both iOS and Mac code even if it's not being used for one platform. So having some classes or methods that are
#ifdef
'ed to Mac, others to iOS, will more often than not lead to compile errors when you switch targets. That means wrapper classes, so that you can write the same code regardless of the platform, are essential.Right now, Cocos2D doesn't offer you to create iOS & Mac targets in the same Xcode project. The way to get there isn't immediately obvious either, because each target requires its own build settings for: Base SDK, SDK Root, Deployment Target, Architectures and possibly Compiler version. It gets worse if you also want to use 3rd party libraries (Box2D, Chipmunk, etc) because in some cases you'll be forced to create iOS and Mac specific targets for those libraries as well - if only to ensure that the library is built with the same compiler as the project's target, otherwise you can run into the strangest build or runtime issues.
I've had issues getting these platform specific targets to work within a single Xcode project without Xcode complaining or otherwise misbehaving. I haven't tried it with Xcode 4.1 and 4.2. By that time I had created .xcconfig files to host the build settings. The .xcconfig files may or may not be necessary with the more recent Xcode versions but they definitely make managing multiple platform-specific targets easier.
Long story short, the best and easiest way to do cross-platform development with cocos2d-iphone is by using Kobold2D.
Most of the 15 template projects have an iOS and Mac target in each project, you just need to select the corresponding scheme, then hit build & run. The most commonly needed platform-specific code (processing user input) is wrapped in a platform-agnostic, simple to use wrapper class KKInput.
Disclaimer: I'm the developer of Kobold2D. There's a slim chance that I may be biased. You should try Kobold2D anyway. :)