标签:
#include "AppDelegate.h" #include "HelloWorldScene.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) // Layer #include "OperateLayer.h" #include "LoginMainLayer.h" #include "OperateUILayer.h" #include "GameSettlementLayer.h" #include "LoadingLayer.h" #include "GameFileLayer.h" #include "ResourceManager.h" #include "SaveMemoryManager.h" #include "TimeLogicManager.h" #include "GameDBManager.h" #include "EntireManage.h" #include "TextJonsManager.h" #include "PhpManager.h" #include "GameConfigManager.h" //sdk #include "SDKConfig.h" #include "RunGameScene.h" #include "AppMacros.h" #include "Utils.h" //audio #include "SimpleAudioEngine.h" #elif(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) // Layer #include "LayerUI/OperateLayer.h" #include "LayerUI/LoginMainLayer.h" #include "LayerUI/OperateUILayer.h" #include "LayerUI/GameSettlementLayer.h" #include "LayerUI/Load/LoadingLayer.h" #include "LayerUI/GameFileLayer.h" #include "Manager/ResourceManager.h" #include "Manager/SaveMemoryManager.h" #include "Manager/TimeLogicManager.h" #include "Manager/GameDBManager.h" #include "Manager/EntireManage.h" #include "Manager/TextJonsManager.h" #include "Manager/PhpManager.h" #include "Manager/GameConfigManager.h" #include "Messager/NotifyMessage.h" //sdk #include "SDK/SDKConfig.h" #include "Scenes/RunGameScene.h" #include "AppMacros.h" #include "Common/Utils.h" #include "platform/CCFileUtilsHelp.h" #include "LayerUI/SelectMapLayer.h" //audio #include "cocos/audio/include/SimpleAudioEngine.h" #endif #if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //#include "MobClickCpp.h" #endif USING_NS_CC; using namespace Utils; AppDelegate::AppDelegate() { cocos2d::log("AppDelegate::AppDelegate"); //进入游戏的时间 gGameDBManager->setEnterTime(TimeLogicManager::shardTime()->LocalTime()); } AppDelegate::~AppDelegate() { //退出游戏的时间 //cocos2d::log("AppDelegate::~AppDelegate"); } bool AppDelegate::applicationDidFinishLaunching() { // initialize director cocos2d::log("AppDelegate::applicationDidFinishLaunching"); auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLViewImpl::create("My Game"); director->setOpenGLView(glview); } std::string strSign = "XXTEASANXIAO136973SIGN"; std::string strKey = "SANXIAO136973KEY"; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) // 设置 encrypt sign和ek encrypt key FileUtilsHelp::getInstance()->setXXTeaKey(strKey.c_str(),::strlen(strKey.c_str()),strSign.c_str(),::strlen(strSign.c_str())); #endif // turn on display FPS //director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don‘t call this director->setAnimationInterval(1.0 / 60); Size frameSize = glview->getFrameSize(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) // 设置窗口大小 glview->setFrameSize(1200.f ,1920.f); //glview->setFrameSize(1080.f ,1920.f); //glview->setFrameSize(480.f ,800.f); //glview->setFrameSize(1200.f ,1920.f); //glview->setFrameSize(720.f,1280.f); //glview->setFrameSize(480.f,854.f); //glview->setFrameSize(480.f,800.f); glview->setFrameZoomFactor(0.3f); //glview->setFrameSize(640,960); //glview->setFrameSize(1080.f * 0.5f,1800.f * 0.5f); //glview->setFrameSize(1200.f * 0.5f,1800.f * 0.5f); #endif frameSize = glview->getFrameSize(); Size designSize = Size(SCREEN_WIDTH, SCREEN_HEIGHT); //将宽和高做一个比,通过这个比,来具体的调整逻辑分辨率的大小 float widthRate = frameSize.width/designSize.width; float heightRate = frameSize.height/designSize.height; //如果是if中的语句,说明逻辑的高度有点大了,就把逻辑的高缩小到和宽度一样的比率 if (widthRate > heightRate) { //里边传入的前俩个参数就是逻辑分辨率的大小,也就是通过getWinSize()得到的大小 designSize.height = designSize.height * heightRate/widthRate; gEntireManage->setViewSacleRate(heightRate/widthRate); } else { designSize.width = designSize.width * widthRate/heightRate; gEntireManage->setViewSacleRate(widthRate/heightRate); } glview->setDesignResolutionSize(designSize.width,designSize.height, ResolutionPolicy::SHOW_ALL); Size frameSize1 = director->getWinSize(); // create a scene. it‘s an autorelease object auto scene = Scene::create(); //auto scene = HelloWorld::createScene(); //友盟sdk #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //MOBCLICKCPP_START_WITH_APPKEY("5506a594fd98c59296000053"); //MOBCLICKCPP_START_WITH_APPKEY_AND_CHANNEL("5506a594fd98c59296000053", "yj_android"); #endif //保存进入游戏时的时间 saveGameEnterTime(); LoadingLayer *pLayer = LoadingLayer::create(); // pLayer->setPositionY(100.f); scene->addChild(pLayer); // run director->runWithScene(scene); #if (LOGIN_PLATFORM_DEFAULT_SDK == PLATFORM_ANDROID_JL_SDK) // 加载游戏配置信息 //gGameConfigManager->loadGameConfig(); // 设置基本信息 //gPhpManager->setDefaultPhpData(); // 发送游戏状态信息到php服务器 //gPhpManager->sendGameStatus(); #endif 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() { //友盟sdk #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //umeng::MobClickCpp::applicationDidEnterBackground(); // 发送游戏状态信息到php服务器 //gPhpManager->sendGameStatus(); #endif Director::getInstance()->stopAnimation(); // if you use SimpleAudioEngine, it must be pause if (gEntireManage->getIsSound()) { CocosDenshion::SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); } //保存离开游戏或异常退出游戏时的时间 saveGameExitTime(); } // this function will be called when the app is active again void AppDelegate::applicationWillEnterForeground() { //cocos2d::log("AppDelegate::applicationWillEnterForeground ==============>>>>>>>>>"); //友盟sdk #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //umeng::MobClickCpp::applicationWillEnterForeground(); // 重置游戏时间 //gPhpManager->resetGameTime(); //滑动地图 NotifyData data; data.type = OPERATE_UI_NOTIFY_COME_BACK; _NOTIFY_->postNotification(OPERATE_UI_NOTIFY_COME_BACK,&data); #endif Director::getInstance()->startAnimation(); // if you use SimpleAudioEngine, it must resume here if (gEntireManage->getIsSound()) { CocosDenshion::SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); } //保存进入游戏时的时间 saveGameEnterTime(); } void AppDelegate::saveGameExitTime() { //存储到数据库中(现有的心所需要的时间+恢复了的时间) int iMinute = gEntireManage->getMinuteNum(); int iSecond = gEntireManage->getSecondNum(); int iNum = gEntireManage->getStaminaNum(); int iTime = (10*60)-(iMinute*60 + iSecond); int iAllTime = iNum*10*60; //储存运行时间 gGameDBManager->setRecoveryTime(iTime + iAllTime); gGameDBManager->setExitTime(TimeLogicManager::shardTime()->LocalTime()); } void AppDelegate::saveGameEnterTime() { //保存进入游戏的时间 gGameDBManager->setEnterTime(TimeLogicManager::shardTime()->LocalTime()); //进入时间逻辑 TimeLogicManager::shardTime()->logicTime(); }
标签:
原文地址:http://www.cnblogs.com/mhh999/p/5431631.html