支持Cocos2d-iphone的iPhone 4高分辨率 [英] support of Cocos2d-iphone for iPhone 4 high res

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

问题描述

我试图创建一个相对简单的游戏与2D图形有一些复杂的动画。我试图用基本的Core Graphics和Core Animation库来开发游戏,但是游戏对象的动画效果不令人满意(即动作/延迟)。



我现在正在研究Cocos2D,它看起来很有前途,直到我检查了iPhone 4的高分辨率支持。这似乎没有工作非常好,但后来,我再次开始研究它。 / p>

文档似乎只是使用CCDirector来设置缩放因子,因此可以这么做:

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

然而,这并没有给出我期望的行为。



在核心图形/动画中,我们需要将所有的像素值加倍,库与我们合作的坐标空间不会改变。在窗帘后面,它只是双打一切,以填补iPhone 4高分辨率屏幕,并使用@ 2x图像可用。这实际上工作得很好,游戏逻辑不需要考虑设备的分辨率。 Cocos2D似乎已经实现了这个相当严重,使我不想去搭载Cocos2D火车。



我发现了一些关于这个主题的其他主题,但没有真正的答案,没有涉及解决方法。这是固定的吗?我做错了或是Cocos2D根本不高res准备好了吗?有没有任何替代Cocos2D可以给我需要什么?

解决方案

对无耻的自我推广,可以帮助你。我最近在cocos2d的高分辨率上写了两个小博客帖子,并把它们放在我们的网站上。



第一个详细介绍了如何获取cocos2d和运行包括如何实现常规vs高分辨率图像的自动加载行为的建议修正。



此外,有一个第二个帖子试图进入一些点和像素之间的差异的详细信息。 UIKit完全基于点,这就是为什么你不必重新工作所有的坐标。与UIKit相反,cocos2d基于像素工作,因此是依赖于分辨率。您可以为cocos2d提供通过一些相当简单的转换来处理点而不是像素的方法。我已经实现这些类别为CCDirector和CCNode,使他们很容易使用。显然,这些类别中的方法不是唯一应该指出的方法。例如,在CCLabel或CCMoveBy的任何位置指定大小是基于像素的,因此也必须重新设置...



查看博客: http://apptech.next-munich.com/ (我会直接链接到



希望这有助于你开始!


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

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.

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.

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.

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?

解决方案

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.

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.

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 ...

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高分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆