2014-06-30 03:25:49 +08:00
|
|
|
#include "AppDelegate.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "GameControllerTest.h"
|
|
|
|
#include "AppMacros.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-25 22:18:57 +08:00
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
2014-06-30 03:25:49 +08:00
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto glview = director->getOpenGLView();
|
|
|
|
if(!glview) {
|
2014-07-31 00:53:04 +08:00
|
|
|
glview = GLViewImpl::create("Game Controller Test");
|
2014-06-30 03:25:49 +08:00
|
|
|
director->setOpenGLView(glview);
|
|
|
|
}
|
|
|
|
|
|
|
|
director->setOpenGLView(glview);
|
|
|
|
|
|
|
|
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
|
|
|
|
|
|
|
|
Size frameSize = glview->getFrameSize();
|
|
|
|
|
|
|
|
vector<string> searchPath;
|
|
|
|
|
|
|
|
// 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(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
|
|
|
|
}
|
|
|
|
// if the frame's height is larger than the height of small resource size, select medium resource.
|
2014-07-04 15:22:53 +08:00
|
|
|
else
|
2014-06-30 03:25:49 +08:00
|
|
|
{
|
|
|
|
searchPath.push_back(mediumResource.directory);
|
|
|
|
|
|
|
|
director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
|
|
|
|
}
|
|
|
|
// set searching path
|
|
|
|
FileUtils::getInstance()->setSearchPaths(searchPath);
|
|
|
|
|
2014-07-04 15:22:53 +08:00
|
|
|
auto scene = Scene::create();
|
|
|
|
GameControllerTest *gameLayer = GameControllerTest::create();
|
|
|
|
scene->addChild(gameLayer);
|
2014-06-30 03:25:49 +08:00
|
|
|
|
|
|
|
director->runWithScene(scene);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-25 22:18:57 +08:00
|
|
|
// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
|
|
|
|
void AppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
2014-06-30 03:25:49 +08:00
|
|
|
Director::getInstance()->stopAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground() {
|
|
|
|
Director::getInstance()->startAnimation();
|
|
|
|
}
|