Hi every one, i have three background image with different size for multi resulution.
The first one background.png with width 640, height 1136, it put this image in Resources\iphone folder
The second one background.png with width 768, height 1024, it put this image in Resources\ipad folder
The last one background.png with width 1536, height 2048, it put this image in Resources\ipadhd folder
In the AppDelegate.cpp i write the code as below.
#include "AppDelegate.h"
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace CocosDenshion;
USING_NS_CC;
// for multi resolution support
typedef struct tagResource
{
cocos2d::Size size;
char directory[100];
}Resource;
static Resource smallResource = { cocos2d::CCSizeMake(480, 320), "iphone" };
static Resource mediumResource = { cocos2d::CCSizeMake(1024, 768), "ipad" };
static Resource largeResource = { cocos2d::CCSizeMake(2048, 1536), "ipadhd" };
static cocos2d::Size designResolutionSize = cocos2d::CCSizeMake(480, 320);
AppDelegate::AppDelegate() {
}
AppDelegate::~AppDelegate()
{
}
//if you want a different context,just modify the value of glContextAttrs
//it will takes effect on all platforms
void AppDelegate::initGLContextAttrs()
{
//set OpenGL context attributions,now can only set six attributions:
//red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLView::setGLContextAttrs(glContextAttrs);
}
// If you want to use packages manager to install more packages,
// don't modify or remove this function
static int register_all_packages()
{
return 0; //flag for packages manager
}
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::create("Save The KoaLa");
director->setOpenGLView(glview);
}
// turn on display FPS
//director->setDisplayStats(true);
director->setDisplayStats(false);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
register_all_packages();
// begin: Set the design
Size screenSize = glview->getFrameSize();
auto fileUtils = FileUtils::getInstance();
std::vector<std::string> searchPath;
// Set the design resolution
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
Size frameSize = glview->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)
{
searchPath.push_back(largeResource.directory);
//director->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)
{
searchPath.push_back(mediumResource.directory);
//director->setContentScaleFactor(mediumResource.size.height / designResolutionSize.height);
}
// if the frame's height is smaller than the height of medium resource size, select small resource.
else
{
searchPath.push_back(smallResource.directory);
//director->setContentScaleFactor(smallResource.size.height / designResolutionSize.height);
}
director->setContentScaleFactor(screenSize.height / designResolutionSize.height);
fileUtils->setSearchPaths(searchPath);
// create a scene. it's an autorelease object
auto scene = HelloWorld::createScene();
// run
director->runWithScene(scene);
return true;
}
I used the cocos2dx v3.6, In the HellowWord Scence i add a background sprite and a close button.
I test the game on windows phone 8.1. My laptop screen size is 14inch (the visible size with the width is 1366 and the height is 768).
When i run the game the background not full my screen, and the close button put in right bottom conner of screen in the black area not inside the background visible area.
I wonder how to calculation the positions for the close button to it put inside the background image area and calculation the positions for other sprites to make sure it not in the black area.
I am sorry about my English.
The attach file show where i want to put the close button.
And i want other object in my game only put in the background image area. Not put in the black side.
Can any one help me. It better if i can make the background fullscreen because the background image is large enough.



