mirror of https://github.com/axmolengine/axmol.git
59 lines
1.8 KiB
C++
59 lines
1.8 KiB
C++
#include "cocos2d.h"
|
|
#include "AppDelegate.h"
|
|
#include "audio/include/SimpleAudioEngine.h"
|
|
#include "base/CCScriptSupport.h"
|
|
#include "scripting/lua-bindings/manual/CCLuaEngine.h"
|
|
#include "scripting/lua-bindings/auto/lua_cocos2dx_controller_auto.hpp"
|
|
#include "scripting/lua-bindings/manual/controller/lua_cocos2dx_controller_manual.hpp"
|
|
|
|
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);
|
|
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
|
|
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();
|
|
}
|