Cocos2d-iphone support for iPhone 4 high res

I am trying to create a relatively simple game with 2D graphics that has some complex animations. I tried to develop a game with the core graphics libraries Core Graphics and Core Animation, but the performance of the animation of the game objects is not satisfactory (i.e., jerky / delayed).

So now I look at Cocos2D, which looked very promising until I tested the high resolution support for iPhone 4. This does not seem to work very well, but again, I just started to peek into it.

The only thing the documentation talks about the problem is that it's easy to use CCDirector to set the scale factor, which can be done as follows:

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

However, this does not give the expected behavior. It just doubles the number of pixels to work, that is, I have to take into account the "double pixel" coefficient in all my code.

In the Core Graphics / Animation libraries, the coordinate space we are working with does not change. Behind the curtains, he simply doubles everything to fill the high-resolution screen of the iPhone 4 and uses @ 2x images, if any. This really works very well, and the game logic does not require device accounting. Cocos2D seems to have implemented this rather poorly, making me not want to go on board Cocos2D.

I found some other topics on this subject, but there were no real answers that didn't deal with workarounds. Is this fixed? Am I doing it wrong or is Cocos2D just not ready? Are there any alternatives to Cocos2D that can give me what I need?

+4
source share
3 answers

Sorry for the shameless self-promotion, but I think it can help you. I recently wrote two small high-definition blog posts on cocos2d and posted them on our website.

The first is detailed information on how to start and run cocos2d, including the proposed fix on how to implement the automatic loading behavior of regular high-resolution images.

In addition, there is a second article trying to go into some details about the difference between points and pixels. UIKit is completely point-based, so you don’t need to recycle all your coordinates. Unlike UIKit, cocos2d is pixel-based and therefore resolution dependent. You can provide cocos2d with tools for working with points rather than pixels through fairly simple conversions. I implemented them as categories for CCDirector and CCNode to simplify their work. Obviously, the methods in these categories are not the only ones that should be "indicated". Sizing on CCLabel or any position on CCMoveBy, for example, is pixel-based and therefore also needs to be reworked ...

Take a look at the blog at: http://apptech.next-munich.com/ (I would directly contact the articles, but as a new user I can send only one link in response).

Hope this helps you and get started!

+3
source

I now understand a fairly simple solution. My progress is published here: http://www.cocos2d-iphone.org/forum/topic/8511#post-50361

You basically scale your texture sources in CCSprite, but nothing more, so you can use the same coordinate system 320x480 (for example, a points system), but you get high-resolution graphics.

You have to combine my technique with this with point 2 of the Benjamin blog here, so you don't get memory problems: http://apptech.next-munich.com/2010/07/high-res-using-cocos2d-on -ios-4.html

+1
source

Cocos2D uses the UIImage methods UIImage imageWithContentsOfFile: and initWithContentsOfFile: which, despite what the documentation says, do not believe the correct @ 2x image versions on iPhone 4.

This is a known bug, and obviously Apple is working on it.

However, some people believe that this is the correct behavior, because it passes the path to a specific file, not the file name, and allows the system to decide which one to use. In this case, I suggested updating the documentation to reflect this fact, if true. Let's see how Apple responds.

0
source

Source: https://habr.com/ru/post/1316315/


All Articles