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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
|
|
|
void AppDelegate::applicationDidEnterBackground() {
|
|
|
|
Director::getInstance()->stopAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground() {
|
|
|
|
Director::getInstance()->startAnimation();
|
|
|
|
}
|