I've just finished upscaling all my images for iPhone 4, and updating cocos2d to 99.4. However, for some reason it isn't using the @2x versions of my PNGs while on the iPhone 4. Here is a sample of my code:
CCSprite *background = [CCSprite spriteWithFile:@"menu_back.png"];
Is there anything else I need to do so it knows to grab menu_back@2x.png if it is running on an iPhone 4?
Thanks!
Using @2x png's
(11 posts) (4 voices)-
Posted 1 year ago #
-
Look at the release notes for 0.99.4, this is discussed.. basically there is a bug in iOS4 where UIImage initWithContentsOfFile fails to pick the @2x file even though the documentation says it does. So a workaround is to use imageNamed, but this returns an autoreleased object, so it can eat up memory. A better solution for now is to pick the right image yourself; you can do this by writing a function that accepts an image name and returns the proper sprite or image name file for you.. then you can continue using spriteWithFile on CCSprites.
Posted 1 year ago # -
Has anybody tested this issue with the latest SDK 4.0.1?
Marco
Posted 1 year ago # -
Hi again,
so now I´ve checked the issue with the latest SDK 4.0.1 and it still seems to exist. Neither in the simulator nor on the iphone 4 device will the @2x image be shown...
Marco
Posted 1 year ago # -
There was a workaround in cocos to be able to use automatic @2x image picking. Look at the release notes on how to enable it, or look in the source code in the texture cache for addImage.
Posted 1 year ago # -
I've followed all the instructions in the release notes, regarding issue 910 and using SpritesTest.m, and indeed it is now using the @2x files, but everything is placed incorrectly on the screen. The size appears to be right but its pushed off into the lower left corner and off the screen. Any ideas?
Thanks!Posted 1 year ago # -
Well, you will need to position things based on the actual pixels on the screen.. UIKit does this for you since it uses points, but OpenGL is pixel-based. There is a good video, all about screen resolutions and how to adapt to the new hardware, on the iPhone developer site from the recent WWDC.
Posted 1 year ago # -
There really isn't any other way? I've read some people have had success with it not influencing the game logic, but they weren't specific. Using 1000 if statements checking if it is a high resolution screen doesn't seem like a very optimized way.
Posted 1 year ago # -
Well if you don't mind the autoreleased image loading route you can try that. I don't do 1000 if statements... I have a function where I pass in a name, much like I would to UIImage's imageNamed, and it returns the proper sprite for me. If there is a better way to do this, until the official api is fixed, I don't know of it.
Posted 1 year ago # -
When running high-res I set a scale factor of 2x on the scene itself; that way I can keep measuring everything in 320x480 size points, kind of like UIkit does. Discussed more in this thread:
http://www.cocos2d-iphone.org/forum/topic/7479
The basic idea is to run everything in a 320x480 scene and blow it up (and load larger graphics) when running high res. Works well so far.
Posted 1 year ago #
Reply
You must log in to post.