问题描述
我们正在创建在cocos2d-X游戏中使用(在Android / iOS版)的SDK。
作为发展的一部分,我们已经建立了(只是在一瞬间的Android)在真实设备上运行的各种测试的测试框架。
一个具体的测试需要终止该应用,然后重新启动。
看来的Cocos2D-X没有为退出(或杀死)运行的应用程序提供任何API。
一些网上资源,建议人们使用了呼叫退出(0)
。
有什么办法要退出的Cocos2D-X游戏?
调用退出(0)
似乎崩溃:
#00件0001e824 /system/lib/libc.so
#01件0001c76c /system/lib/libc.so(中止+ 4)
#02件000122ed /system/lib/libc.so
#03件00010f9d /system/lib/libc.so(dlfree + 1184)
#04件0000dabf /system/lib/libc.so(免费+ 10)
#05件000cbf59 /data/app-lib/com.test.cocos2dx_testapp-1/libhellocpp.so(cocos2d的:: BitmapDC ::〜BitmapDC()+ 10)
#06件00024639 /system/lib/libc.so(__cxa_finalize + 156)
#07件000248f1 /system/lib/libc.so(出口+ 6)
示例项目HelloCpp在其示例的退出按钮。看看HelloWorldScene.cpp,在函数调用回menuCloseCallback(功能基于版本cocos2dx的你是可能会有所不同位)
无效的HelloWorld :: menuCloseCallback(CCObject * pSender)
{
#如果(CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)|| (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox(你pressed的关闭按钮,Windows应用商店的应用程序没有实现关闭按钮。,警报);
#其他
CCDirector :: sharedDirector() - GT;结束();
#如果(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
出口(0);
#万一
#万一
}
针对Android答案是CCDirector :: sharedDirector() - >结束();
请注意,我不认为苹果会批准你,如果你的应用程序调用exit(0)。
We are creating an SDK that is used in Cocos2d-x games (on Android/iOS).
As part of development, we have setup a test framework for running various tests on a real device (Android only at the moment).
One specific test needs to kill the app and launch it again.
It seems that Cocos2d-x does not provide any API for exiting (or killing) the running app.
Some online resources suggested that people have used the call to exit(0)
.
Is there any way to exit the game from Cocos2d-x ?
Calling exit(0)
seems to crash:
#00 pc 0001e824 /system/lib/libc.so
#01 pc 0001c76c /system/lib/libc.so (abort+4)
#02 pc 000122ed /system/lib/libc.so
#03 pc 00010f9d /system/lib/libc.so (dlfree+1184)
#04 pc 0000dabf /system/lib/libc.so (free+10)
#05 pc 000cbf59 /data/app-lib/com.test.cocos2dx_testapp-1/libhellocpp.so (cocos2d::BitmapDC::~BitmapDC()+10)
#06 pc 00024639 /system/lib/libc.so (__cxa_finalize+156)
#07 pc 000248f1 /system/lib/libc.so (exit+6)
The sample project HelloCpp has an exit button in its example. Look at HelloWorldScene.cpp and at the function call back menuCloseCallback (function might vary a bit based on version of cocos2dx you are on)
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}
For android the answer would be CCDirector::sharedDirector()->end();
Note that I don't think Apple will approve you if your app calls exit(0).
这篇关于如何杀死的Cocos2D-X的测试应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!