Cocos2d-iphone 支持 iPhone 4 高分辨率

support of Cocos2d-iphone for iPhone 4 high res(Cocos2d-iphone 支持 iPhone 4 高分辨率)

本文介绍了Cocos2d-iphone 支持 iPhone 4 高分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 2D 图形创建一个相对简单的游戏,其中包含一些复杂的动画.我尝试使用基本的 Core Graphics 和 Core Animation 库开发游戏,但游戏对象的动画性能并不令人满意(即抖动/延迟).

I'm trying to create a relatively simple game with 2D graphics which has somewhat complicated animations. I tried to develop the game with the basic Core Graphics and Core Animation libraries but the animation performance of the game objects is not satisfactory (i.e. jerky/delayed).

所以,我现在正在研究 Cocos2D,它看起来非常有前途,直到我检查了对 iPhone 4 的高分辨率支持.这似乎根本不能很好地工作,但话又说回来,我刚刚开始调查一下.

So, I am now looking into Cocos2D which looked very promising until I checked into the high resolution support for the iPhone 4. This doesn't seem to work very well at all, but then again, i've just started to look into it.

文档似乎对这个问题说了一件事,因此只需使用 CCDirector 设置比例因子,可以这样完成:

The one thing the documentation seems to say about the issue it so simply use the CCDirector to set the scale factor, which can be done like so:

if( [[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    [[CCDirector sharedDirector] setContentScaleFactor: [[UIScreen mainScreen] scale] ];
}

但是,这并没有给出我期望的行为.它只是将要使用的像素数量增加了一倍,这意味着我必须在我的所有代码中考虑双像素因素".

However, this doesn't give the behavior I expect. It simply doubles the amount of pixels to work with, meaning I have to take the 'double pixels factor' into account in all my code.

在核心图形/动画库中,我们使用的坐标空间不会改变.在窗帘后面,它只是将所有内容加倍以填充 iPhone 4 高分辨率屏幕,并在可用的情况下使用@2x 图像.这实际上效果很好,游戏逻辑不需要考虑设备的分辨率.Cocos2D 的实现似乎很糟糕,让我不想登上 Cocos2D 的火车.

In the Core Graphics/Animation libraries the coordinate space we work with doesn't change. Behind the curtains it simply doubles everything to fill the iPhone 4 high res screen and uses the @2x images where available. This actually works very well and the game logic need not take the device's resolution into account. Cocos2D seems to have implemented this pretty badly, making me not want to go onboard the Cocos2D train.

我发现了一些关于该主题的其他主题,但没有不涉及变通办法的真正答案.这是要修复的吗?是我做错了还是 Cocos2D 根本没有准备好高分辨率?有没有 Cocos2D 的替代品可以满足我的需求?

I found some other topics on the subject but there were no real answers that didn't involve workarounds. Is this being fixed? Am I doing it wrong or is Cocos2D simply not high res ready? Are there any alternatives to Cocos2D which can give me what I need?

推荐答案

对不起,无耻的自我推销,但我想它可以帮助你.我最近在cocos2d上写了两篇关于高分辨率的小博文,放到了我们的网站上.

Sorry for the shameless self-promotion but I guess it can help you out. I've written two small blog posts on high res in cocos2d recently and put them up on our website.

第一个详细介绍了如何启动和运行 cocos2d,包括针对如何实现常规图像和高分辨率图像的自动加载行为的建议修复.

The first one goes into detail as to how to get cocos2d up and running including a proposed fix for how to implement the auto-loading behaviour of regular vs high-res images.

此外,还有第二篇文章试图详细介绍点和像素之间的差异.UIKit 完全基于点,这就是为什么您不必重新处理所有坐标的原因.与 UIKit 相比,cocos2d 基于像素工作,因此依赖于分辨率.您可以通过一些相当简单的转换为 cocos2d 提供使用点而不是像素的方法.我已经将它们实现为 CCDirector 和 CCNode 的类别,以使它们易于使用.显然,这些类别中的方法并不是唯一应该指出"的方法.例如,在 CCLabel 上指定尺寸或在 CCMoveBy 上的任何位置都是基于像素的,因此也必须重新设计......

Additionally, there is a second post trying to go into some details on the difference between points and pixels. UIKit is entirely based on points which is why you do not have to re-work all your coordinates. In contrast to UIKit, cocos2d works based on pixels and is therefore resolution-dependent. You can provide cocos2d with the means to work with points rather than pixels through some rather simple conversions. I've implemented those as categories for CCDirector and CCNode to make them easy to work with. Obviously, the methods in these categories are not the only ones one should "pointify". Specifying sizes on CCLabel or any positions on CCMoveBy, for example, are pixel-based and thus would have to be reworked also ...

查看博客:http://apptech.next-munich.com/(我会直接链接到文章,但作为新用户,我只能在答案中发布一个链接).

Have a look at the blog at: http://apptech.next-munich.com/ (I would've directly linked to the articles but as a new user I can only post a single link in an answer).

希望这对您有所帮助并帮助您入门!

Hope this helps and gets you started!

这篇关于Cocos2d-iphone 支持 iPhone 4 高分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Cocos2d-iphone 支持 iPhone 4 高分辨率

基础教程推荐