2013-02-19 15:38:30 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "CCEGLView.h"
|
|
|
|
#include "AppDelegate.h"
|
|
|
|
#include "CCLuaEngine.h"
|
|
|
|
#include "SimpleAudioEngine.h"
|
|
|
|
|
|
|
|
using namespace CocosDenshion;
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
SimpleAudioEngine::end();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
|
|
|
// initialize director
|
2013-09-17 21:01:43 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-28 00:16:16 +08:00
|
|
|
director->setOpenGLView(EGLView::getInstance());
|
2013-02-19 15:38:30 +08:00
|
|
|
|
2013-09-17 21:01:43 +08:00
|
|
|
EGLView::getInstance()->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
|
|
|
|
|
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
|
|
|
|
|
|
|
// register lua engine
|
2013-09-17 21:01:43 +08:00
|
|
|
auto engine = LuaEngine::getInstance();
|
2013-07-28 00:16:16 +08:00
|
|
|
ScriptEngineManager::getInstance()->setScriptEngine(engine);
|
2013-06-10 14:20:53 +08:00
|
|
|
|
2013-07-12 12:03:39 +08:00
|
|
|
std::string path = FileUtils::getInstance()->fullPathForFilename("hello.lua");
|
2013-07-28 00:16:16 +08:00
|
|
|
engine->executeScriptFile(path.c_str());
|
2013-02-20 12:01:47 +08:00
|
|
|
|
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
|
|
|
|
2013-07-24 17:27:29 +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
|
|
|
|
2013-07-24 17:27:29 +08:00
|
|
|
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
2013-02-19 15:38:30 +08:00
|
|
|
}
|