From 230899ae32635c44511aa51306a0440396bf6750 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Fri, 5 Jun 2015 09:39:15 +0800 Subject: [PATCH] issue #10257:Fix the error that Draw object display differently on the different platform. --- .../Classes/AppDelegate.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/templates/cpp-template-default/Classes/AppDelegate.cpp b/templates/cpp-template-default/Classes/AppDelegate.cpp index aa547b34aa..3aa4f443df 100644 --- a/templates/cpp-template-default/Classes/AppDelegate.cpp +++ b/templates/cpp-template-default/Classes/AppDelegate.cpp @@ -3,6 +3,11 @@ USING_NS_CC; +static cocos2d::Size designResolutionSize = cocos2d::Size(480, 320); +static cocos2d::Size smallResolutionSize = cocos2d::Size(480, 320); +static cocos2d::Size mediumResolutionSize = cocos2d::Size(1024, 768); +static cocos2d::Size largeResolutionSize = cocos2d::Size(2048, 1536); + AppDelegate::AppDelegate() { } @@ -44,6 +49,25 @@ bool AppDelegate::applicationDidFinishLaunching() { // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); + // Set the design resolution + glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER); + Size frameSize = glview->getFrameSize(); + // if the frame's height is larger than the height of medium size. + if (frameSize.height > mediumResolutionSize.height) + { + director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width)); + } + // if the frame's height is larger than the height of small size. + else if (frameSize.height > smallResolutionSize.height) + { + director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width)); + } + // if the frame's height is smaller than the height of medium size. + else + { + director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width)); + } + register_all_packages(); // create a scene. it's an autorelease object