2013-02-19 15:38:30 +08:00
|
|
|
#include "AppDelegate.h"
|
|
|
|
#include "HelloWorldScene.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-22 16:22:16 +08:00
|
|
|
//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);
|
|
|
|
}
|
|
|
|
|
2013-02-19 15:38:30 +08:00
|
|
|
bool AppDelegate::applicationDidFinishLaunching() {
|
|
|
|
// initialize director
|
2013-09-19 07:50:26 +08:00
|
|
|
auto director = Director::getInstance();
|
2014-01-31 13:17:55 +08:00
|
|
|
auto glview = director->getOpenGLView();
|
|
|
|
if(!glview) {
|
2014-07-31 00:53:04 +08:00
|
|
|
glview = GLViewImpl::create("My Game");
|
2014-01-31 13:17:55 +08:00
|
|
|
director->setOpenGLView(glview);
|
|
|
|
}
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// turn on display FPS
|
2013-07-28 00:16:16 +08:00
|
|
|
director->setDisplayStats(true);
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// set FPS. the default value is 1.0/60 if you don't call this
|
2013-07-28 00:16:16 +08:00
|
|
|
director->setAnimationInterval(1.0 / 60);
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// create a scene. it's an autorelease object
|
2013-09-19 07:50:26 +08:00
|
|
|
auto scene = HelloWorld::createScene();
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// run
|
2013-07-28 00:16:16 +08:00
|
|
|
director->runWithScene(scene);
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
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() {
|
2013-07-12 11:50:36 +08:00
|
|
|
Director::getInstance()->stopAnimation();
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// if you use SimpleAudioEngine, it must be pause
|
2014-04-22 13:20:07 +08:00
|
|
|
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
2013-02-19 15:38:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground() {
|
2013-07-12 11:50:36 +08:00
|
|
|
Director::getInstance()->startAnimation();
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// if you use SimpleAudioEngine, it must resume here
|
2014-04-22 13:20:07 +08:00
|
|
|
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
2013-02-19 15:38:30 +08:00
|
|
|
}
|