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.
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:
CCSprite* coolSprite = CCSprite::create(“sprite.png”) <- Notice that you just ask for “sprite.png”. Then cocos2d-x will load the necessary asset for you.
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!
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.
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).
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); }