auto label = Label::createWithTTF(“Hello World”, “fonts/Marker Felt.ttf”, 24);
label->setPosition(100, 100);
setPosition 出sigsegv错误,我猜测是字体没被打包进去,然后我把Resources目录拷贝到asset下,还是报错。
我是现在用命令行python脚本建立项目,然后在adt里面import的proj.android,然后调试就报错。
环境:windows10,android-ndk-r10,cocos2d-x 3.11.1,adt
需要怎么操作?
完整代码:
#include
“HelloWorldScene.h”
#include
“SimpleAudioEngine.h”
USING_NS_CC;
Scene* HelloWorld::createScene()
// ‘scene’ is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
void CCLogError(const char * pszFormat, …)
va_list args;
va_start(args, pszFormat);
va_end(args);
__android_log_print(ANDROID_LOG_ERROR, “cocos2d-x debug info”, pszFormat, args);
// on “init” you need to initialize your instance
bool HelloWorld::init()
CCLogError(“init 0”);
if ( !Layer::init() )
return false;
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
CCLogError("init 1\norigin.x= %ld, \nvisibleSize.width=%f", origin.x, visibleSize.width);
CCLogError("==========================1=============================A");
auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
CCLogError("==========================2=============================");
label->setPosition(100, 100);
CCLogError("==========================3=============================");
this->addChild(label, 1);
CCLogError("==========================4=============================");
return true;
void HelloWorld::menuCloseCallback(Ref* pSender)
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
操作步骤:
1、打开cmd,执行:python cocos.py new HelloWorldCpp -p com.coco2dx.org -l cpp -d D:\cocos2dProjects
2、打开adt,选择file-> import -> android -> Existing Android code into workspace,选择D:\cocos2dProjects\HelloWorld
3、adt,右键点击HelloWorld项目->debug as->Android application
经过加入log,发现是在label->setPosition(100, 100);这行出错。