cocos2dx3.13 lua注册、分发监听真机切到后台事件
2016-11-26 13:40
1311 查看
-----------------解决方法(直接上代码):
1.AppDelegate.cpp:
void AppDelegate::applicationDidEnterBackground()
{
Director::getInstance()->stopAnimation();
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("APP_ENTER_BACKGROUND_EVENT");
}
void AppDelegate::applicationWillEnterForeground()
{
Director::getInstance()->startAnimation();
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("APP_ENTER_FOREGROUND_EVENT");
}
2.监听事件
local listenerCustom=cc.EventListenerCustom:create("APP_ENTER_FOREGROUND_EVENT",function ()
print("切换到前台")
end)
local customEventDispatch=cc.Director:getInstance():getEventDispatcher()
customEventDispatch:addEventListenerWithFixedPriority(listenerCustom, 1)
-----------------说明:
1.正常的按照c++的方式应该是:
cc.Director:getInstance():getEventDispatcher():addCustomEventListener("APP_ENTER_FOREGROUND_EVENT", function ()
print("========= 前台")
end)
但lua-binding对c++的该方法不支持回调方法。该lua-binding方法在lua_cocos2dx_auto.cpp中的
int lua_cocos2dx_EventDispatcher_addCustomEventListener(lua_State* tolua_S)方法,其中
do {
// Lambda binding for lua is not supported.
assert(false);
}
while(0)
直观的告诉你,不支持回调方法。
2.cocos2dx-quick3.3中可以使用:
app:addEventListener("APP_ENTER_FOREGROUND_EVENT", function(event)
print("========= 前台")
end)
但quick3.3和cocos2dx3.13中的AppBase实现方式不一样,导致app:addEventListener找不到。
3.所以3.13中用上述方法来注册、分发监听事件
1.AppDelegate.cpp:
void AppDelegate::applicationDidEnterBackground()
{
Director::getInstance()->stopAnimation();
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("APP_ENTER_BACKGROUND_EVENT");
}
void AppDelegate::applicationWillEnterForeground()
{
Director::getInstance()->startAnimation();
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("APP_ENTER_FOREGROUND_EVENT");
}
2.监听事件
local listenerCustom=cc.EventListenerCustom:create("APP_ENTER_FOREGROUND_EVENT",function ()
print("切换到前台")
end)
local customEventDispatch=cc.Director:getInstance():getEventDispatcher()
customEventDispatch:addEventListenerWithFixedPriority(listenerCustom, 1)
-----------------说明:
1.正常的按照c++的方式应该是:
cc.Director:getInstance():getEventDispatcher():addCustomEventListener("APP_ENTER_FOREGROUND_EVENT", function ()
print("========= 前台")
end)
但lua-binding对c++的该方法不支持回调方法。该lua-binding方法在lua_cocos2dx_auto.cpp中的
int lua_cocos2dx_EventDispatcher_addCustomEventListener(lua_State* tolua_S)方法,其中
do {
// Lambda binding for lua is not supported.
assert(false);
}
while(0)
直观的告诉你,不支持回调方法。
2.cocos2dx-quick3.3中可以使用:
app:addEventListener("APP_ENTER_FOREGROUND_EVENT", function(event)
print("========= 前台")
end)
但quick3.3和cocos2dx3.13中的AppBase实现方式不一样,导致app:addEventListener找不到。
3.所以3.13中用上述方法来注册、分发监听事件
相关文章推荐
- Android设备 cocos2dx 骨骼动画注册事件播放音效,退到后台再返回黑屏问题
- cocos2dx的注册时间监听事件
- cocos2dx中lua注册事件函数详解
- cocos2dx lua 使用cocostudio编辑的动画文件并监听帧事件
- [cocos2dx]事件分发机制--lua源码(二)
- 项目后期Lua接入笔记06--按钮事件监听及消息分发
- 4------关于在Cocos2dx中注册触摸事件——Lua(单点触摸)
- Lua_Cocos2dx 3.x版本中Lua注册事件函数
- cocos2dx+lua 3.1.1 注册事件函数详解
- Cocos2d 多触点与触屏事件详解(单一监听、事件分发)
- flex4事件监听与自定义事件分发(二)
- (后台)Openbravo如何实现业务事件监听处理
- [置顶] flex4事件监听与自定义事件分发(三)
- flex4事件监听与自定义事件分发(三)
- cocos2dx监听home键,锁屏,后台转前台暂停功能
- cocos2dx监听home键,锁屏,后台转前台暂停功能
- cocos2dx监听home键,锁屏,后台转前台暂停功能
- ActionScript3(AS3)类库学习之(五)——EventDispatcher事件分发和监听
- cocos2dx 中触摸事件分发一些解读
- Android 程式开发:(十一)监听UI事件 —— 11.2为view注册监听