Problem with setContentScaleFactor functions

Hello!

I have a problem with usage setContentScaleFactor function in my iOS project. I’m try to scale my game for iPhone 3. It looks like
@
NSString *deviceType = [UIDevice currentDevice].model;
NSLog("deive name is %“,deviceType);
if([deviceType isEqualToString:"iPad"] || [deviceType isEqualToString:”iPad Simulator"] ){
cocos2d::CCDirector::sharedDirector()->setContentScaleFactor(1);
}
else {
if([[UIScreen mainScreen] respondsToSelector:NSSelectorFromString(`“scale”)]){
if ([[UIScreen mainScreen] scale] < 1.1){
cocos2d::CCDirector::sharedDirector()->setContentScaleFactor(0.5);
}
if ([[UIScreen mainScreen] scale] > 1.9){
//retina display
cocos2d::CCDirector::sharedDirector()->setContentScaleFactor(2);
}
}
else{
cocos2d::CCDirector::sharedDirector()->setContentScaleFactor(1);
}
}

`

This is code from applicationdidFinishLaunchingWithOptions functions in AppController.mm.

So, setContentScaleFactor(0.5) does not make game content less. Contrary, this function making content big.

Can someone help me![](?

Thank you very much)

hi. I think you have the wrong idea (totally wrong I guess) on how to implement the different resolutions on iOS. There is a tutorial about this in the wiki of this website.

The basic idea is: you enable the retina display, and if the device doesn’t support it will not obviously enable it. Then you have to have a version for retina and non retina devices. For instance:

sprite.png
sprite-hd.png
sprite-ipad.png
sprite-ipadhd.png

and then load the sprite this way:

CCSprite* coolSprite = CCSprite::create(“sprite.png”) <- Notice that you just ask for “sprite.png”. Then cocos2d-x will load the necessary asset for you.

More info in the wiki.

Good luck.

Cheers from Catalonia

Hi!

As i understood, you offer to me create different sprites for different devices. Is there really no other way? My application working good with iPod and iPad devices.
I have a problem only with iPhone. I was trying to enable retina display, but it did not help. i think (but may be it really wrong) that setContentScaleFactor function will help
me to scale game content. But if i use this function with parameter=2.0 i have the same result as if i was trying to use it with parameter=0.5. I dont understand what happening!

Thank you

I understood the advice, but I can not afford to have the different set of content for different devices. I really want to get advice as soon as possible about another way how to solve the problem.
Please, help me.

Don’t enable retina on ipad3 and use your iPad assets??!

Martyn Korbut wrote:

But if i use this function with parameter=2.0 i have the same result as if i was trying to use it with parameter=0.5. I dont understand what happening!

I’m experiencing the same behavior here and I can’t understand why.
I’m trying to port a BB10 game (design resolution: 1280x768, landscape mode) to iOS (frame resolution: 960x640, landscape mode). I expected that setting the content scale factor to (float)960/1280 would automatically resize all the sprites and coordinates on the fly to make them fit the smaller resolution, but it turns out it actually makes them bigger (although the ratio is < 1.0).

Does anyone know what’s going on here?

Thanks!

Not sure if you still have this issue (the last comment guy)
But I was just looking around into the ContentScaleFactor and found you were misunderstanding things.

Haven’t tried myself but I guess that’s how things are here. (Purely logical, just need to think over what’s happening inside)

You are confusing the frameSize with the resource Size.

If you look into the AppDelegate.cpp,

if (frameSize.height > mediumResource.size.height) { CCFileUtils::sharedFileUtils()->setResourceDirectory(largeResource.directory); pDirector->setContentScaleFactor(largeResource.size.height/designResolutionSize.height); } // if the frame's height is larger than the height of small resource size, select medium resource. else if (frameSize.height > smallResource.size.height) { CCFileUtils::sharedFileUtils()->setResourceDirectory(mediumResource.directory); pDirector->setContentScaleFactor(mediumResource.size.height/designResolutionSize.height); } // if the frame's height is smaller than the height of medium resource size, select small resource. else { CCFileUtils::sharedFileUtils()->setResourceDirectory(smallResource.directory); pDirector->setContentScaleFactor(smallResource.size.height/designResolutionSize.height); }

What cocos2d would ussually do in your case is

768 / 1280 = 0.6 (768 -> Check the appmacros.h)

And what you are doing is

960 / 1280 = 0.75.

And so you see everything getting bigger.

Going to try this myself tomorrow :slight_smile: