如题,想实现在游戏退出时保存数据,该怎么做
// This function will be called when the app is inactive. When comes a phone call,it’s be invoked too
void AppDelegate::applicationDidEnterBackground()
{
struct CustomEvent event;
event.name = EVENT_COME_TO_BACKGROUND;
EventDispatcher::dispatchCustomEvent(&event);
EventDispatcher::dispatchEnterBackgroundEvent();
}
cc.game.on(cc.game.EVENT_HIDE)
请问解决嘛?cc.game.on(cc.game.EVENT_HIDE)这个函数确实只有切到后台才会执行,直接关闭程序不会执行。
楼主如果解决了能不能讲一下方法,在此感谢!
退出游戏有2种情况 第一种点击游戏内的退出按钮 第二种切到手机主界面 打开管理栏干掉程序 第一种在退出前执行自己的函数就OK 第二种执行cc.game.on(cc.game.EVENT_HIDE)的回调 这应该能满足需求吧
我刚试了,第二种方式cc.game.on(cc.game.EVENT_HIDE)的回调是不会执行的。。
回调 会执行的 cc.game.on(cc.game.EVENT_HIDE, function () {
if (cc.vv.room.gameState >= 3) {
this._gameNum = cc.vv.room.currentGameNumber;
}
}.bind(this));
cocos介绍的也说明了这个函数不一定会触发