Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should cocos2d-iphone users avoid using the @2x file extension?

Cocos2d-iphone uses the -hd extension for Retina images (and other assets). The cocos2d Retina guide speaks only vaguely of "some incompatibilities" regarding @2x:

Apple uses the ”@2x” suffix, but cocos2d doesn't use that extension because of some incompatibilities. Instead, cocos2d has its own suffix: ”-hd”.

WARNING: It is NOT recommend to use the ”@2x” suffix. Apple treats those images in a special way which might cause bugs in your cocos2d application.

Great. I feel well informed.

Through a 2-year old bug report regarding @2x I got the link to a forum thread that supposedly explains the issues with @2x. However, it does not. The only hints I found in there is that there are iOS (4.0/4.1) bugs regarding @2x which I suppose are no longer relevant. It's possible that I might have missed some crucial aspect (there was some talk about caching or repeat loading issues) - the thread is very long after all.

I'd like to know what specific issues might a cocos2d developer encounter if (s)he is using the @2x suffix for images instead of -hd?

Please give concrete examples of things that might go or actually will be wrong.

like image 628
LearnCocos2D Avatar asked Jun 09 '12 12:06

LearnCocos2D


2 Answers

This seems to be the main reason from this link: http://www.cocos2d-iphone.org/forum/topic/12026

Specifically this post by riq:

I don't know if initWithContentsOfFile was fixed, but in 4.0 it was broken and it wasn't working with @2x, ~iphone extensions. imageNamed caches all the loaded files so it consumes much more memory than initWithContentsOfFile Also the @2x extension does something (I don't know exactly what) but it doesn't work OK with cocos2d.

Another good point: Back when the iPhone 4 was just released with the retina display, I am sure some users of Cocos2D were using an older version of it so when the user was using the retina display on a version of Cocos2D that didn't support it, things were twice as large as they should've been. Again this is now fixed to most unless you are using a VERY early version of Cocos2D.

Overview, so it seems that the main issue was with initWithContentsOfFile from iOS 4 but they have fixed this since because I use that exact API with Cocos2D 2.0-rc2 in my app and I do not have any issues whatsoever. I use all Apple specified extensions for images and everything works jolly good! :)

like image 164
SimplyKiwi Avatar answered Oct 15 '22 16:10

SimplyKiwi


It seems as if this has a historic background.

What makes using -hd graphics still worthwhile is that loading them doesn't rely on Apple functionality but is rather done in framework code. So -hd can be loaded for iPads in iPhone Simulator mode and make use of the higher resolution pictures in 2x mode.

Other than that I couldn't find any more reasons to not use @2x when I was looking into this a week ago.

In case you want all the details it is probably best to drop riq an email.

like image 28
Lennert Avatar answered Oct 15 '22 17:10

Lennert