2014-07-09 18:05:02 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "AppDelegate.h"
|
|
|
|
#include "audio/include/SimpleAudioEngine.h"
|
|
|
|
#include "base/CCScriptSupport.h"
|
|
|
|
#include "CCLuaEngine.h"
|
2014-07-11 11:52:05 +08:00
|
|
|
#include "scripting/lua-bindings/auto/lua_cocos2dx_controller_auto.hpp"
|
2014-08-04 09:39:42 +08:00
|
|
|
#include "scripting/lua-bindings/manual/controller/lua_cocos2dx_controller_manual.hpp"
|
2014-07-09 18:05:02 +08:00
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace CocosDenshion;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
// fixed me
|
|
|
|
//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
// end simple audio engine here, or it may crashed on win32
|
|
|
|
SimpleAudioEngine::getInstance()->end();
|
|
|
|
//CCScriptEngineManager::destroyInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
|
|
|
LuaEngine* engine = LuaEngine::getInstance();
|
|
|
|
ScriptEngineManager::getInstance()->setScriptEngine(engine);
|
2014-07-11 11:52:05 +08:00
|
|
|
LuaStack* stack = engine->getLuaStack();
|
|
|
|
lua_State* L = stack->getLuaState();
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS )
|
|
|
|
lua_getglobal(L, "_G");
|
|
|
|
if (lua_istable(L,-1))//stack:...,_G,
|
|
|
|
{
|
|
|
|
register_all_cocos2dx_controller(L);
|
|
|
|
register_all_cocos2dx_controller_manual(L);
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);//statck:...
|
|
|
|
#endif
|
2014-07-09 18:05:02 +08:00
|
|
|
engine->executeString("require 'src/main.lua'");
|
|
|
|
|
|
|
|
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();
|
|
|
|
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
|
|
|
Director::getInstance()->startAnimation();
|
|
|
|
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
|
|
|
}
|