Export to GitHub

cocos2d-iphone - issue #910

Cocos2d does not use high-res images @2x


Posted on Jul 2, 2010 by Massive Bear

See attached file.

What is the expected output? What do you see instead? Cocos2d should use the high-res image, but uses the low-res one.

What cocos2d version are you using ? 4.0

What iPhoneSDK are you using ? cocos2d-iphone-0.99.4-rc2

Attachments

Comment #1

Posted on Jul 2, 2010 by Massive Lion

(No comment was entered for this change.)

Comment #2

Posted on Jul 2, 2010 by Massive Lion

It's a iOS4 bug: https://devforums.apple.com/message/231819

But I'll try to add a workaround...

Comment #3

Posted on Jul 14, 2010 by Massive Lion

(No comment was entered for this change.)

Comment #4

Posted on Jul 17, 2010 by Quick Cat

Hi riq!

Why not use a workaround similar to this in CCTextureCache before loading the image using "initWithContentsOfFile":

if ([[CCDirector sharedDirector] contentScaleFactor] == 2.0) { // check whether there is a highres version of the image
NSString* ext = [fullpath pathExtension]; NSString* p = [fullpath stringByDeletingPathExtension]; NSString* highres = [NSString stringWithFormat:@"%@@2x.%@", p, ext];

if ([[NSFileManager defaultManager] fileExistsAtPath:highres]) { fullpath = highres; } }

In my experience this seems to work well. If you additionally added the following code to the AppDelegate in the cocos templates, most iOS 4 high resolution questions on the forums would probably vanish :-)

// Enables High Res mode on iPhone 4 and maintains low res on all other devices if ([UIScreen instancesRespondToSelector:@selector(scale)]) { [director setContentScaleFactor:[[UIScreen mainScreen] scale]]; }

Hope this helps,

Ben

Comment #5

Posted on Jul 17, 2010 by Massive Lion

@ben thanks. I'll keep them in mind.

Comment #6

Posted on Sep 10, 2010 by Massive Lion

fixed.

cocos2d, if retina display mode is enabled, it will try to load "-hd" images.

eg: "sprite.png" -> "sprite-hd.png". If "sprite-hd.png" doesn't exist, then it will try to load "sprite.png".

Comment #7

Posted on Sep 10, 2010 by Massive Bear

"if retina display mode is enabled"

What does this mean exactly? Do I as a developer have to do anything to enable the retina display mode, or does cocos2d detect if there's a retina display itself, or do you mean that cocos2d checks for contentScale?

Comment #8

Posted on Sep 10, 2010 by Massive Lion

@SweKenchu:

// Enables High Res mode on iPhone 4 and maintains low res on all other devices if ([UIScreen instancesRespondToSelector:@selector(scale)]) { [director setContentScaleFactor:[[UIScreen mainScreen] scale]]; }

Comment #9

Posted on Sep 17, 2010 by Helpful Giraffe

Why "-hd" rather than "@2x"?

Comment #10

Posted on Sep 17, 2010 by Massive Lion

"@2x" has several issues. they are described in this thread: http://www.cocos2d-iphone.org/forum/topic/8511

Status: Fixed

Labels:
Type-Defect Priority-Medium Milestone-Release0.99.5