Good afternoon!
I’m doing some tests on multi resolutions and noticed that the image is only scaled in height … example, if I have a device with a resolution of 1024x600 and 1024x768 have a picture … This works, but if you have a device with 980x600 and 1024x768 picture … The width is not adjusted … Please … How can I create a project that reset the image size in width and height?
Thank you!
Caitano Diniz wrote:
Good afternoon!
I’m doing some tests on multi resolutions and noticed that the image is only scaled in height … example, if I have a device with a resolution of 1024x600 and 1024x768 have a picture … This works, but if you have a device with 980x600 and 1024x768 picture … The width is not adjusted … Please … How can I create a project that reset the image size in width and height?
>
Thank you!
Please someone help me … Thank you!
In the AppDelegate file, you will see this part:
// Set the design resolution
pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);
CCSize frameSize = pEGLView->getFrameSize();
// In this demo, we select resource according to the frame's height.
// If the resource size is different from design resolution size, you need to set contentScaleFactor.
// We use the ratio of resource's height to the height of design resolution,
// this can make sure that the resource's height could fit for the height of design resolution.
// if the frame's height is larger than the height of medium resource size, select large resource.
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 it does it sets the contentScaleFactor
of your app’s assets depending on the frame size vs. design size.
In there you will see *pDirector~~>setContentScaleFactor;*
What you want to do is to change it so that it will set the contentScaleFactor relative to BOTH width and height.
Something like:
<pre>
// Resource factor
float resFactor = MIN;
// Design factor
float desFactor = MIN;
// Set the app’s contentScaleFactor
pDirector~~> setContentScaleFactor( resFactor / desFactor );
Thank you for the reply!
but it does not change anything because the screen is in landscape … this way, he will only adjusting the height …
In my opnion Director should have the class:
setContentScaleXFactor
setContentScaleYFactor
Please see my example and tell me if you can help:
Without modifying the example HelloCpp (Cocos2d-2.0-x-2.0.4).
I have two android devices: Tablet (1024x600) and Mobile (480x320) …
Rule: kResolutionNoBorder
In Mobile: Selects the Picture 480x320, but cuts in width and height.
In Tablet: Select Picture: 1024x768, but cuts in width and height.
Rule: kResolutionNoBorder
In Mobile: Selects the Picture 480x320, cut width being only …
In Tablet: It is perfect …
The example HelloCpp works perfectly for you guys?
Open up AppMacros.h, there you will see this part:
/* If you want to switch design resolution, change next line */
#define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_480X320
Replace DESIGN_RESOLUTION_480X320 to either of the following:
- DESIGN_RESOLUTION_480X320
- DESIGN_RESOLUTION_1024X768
- DESIGN_RESOLUTION_2048X768
You should choose which resolution your resources are based on. In my case, they were based on iPhone resolution, so I used DESIGN_RESOLUTION_480X320.
Okay thank you very much!
But I think there is a way to encapsulate this choice … ’ll think better …
Thank you!