I am very new to android development and cocos2d-x. I noticed that the document says it has to be ndk r4 or r5. but I could not get r4 or r5 compile. I got the error message says:
android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-ar: No such file or directory
But I can get it compile for ndk r7. But the problem I have is the when I run it, the program just crashes and exit when I touch the screen.
If I just run a sprite even with animation it works fine with out the exit menu.
but If I add the exit menu that comes with the example, anywhere I touch the screen, the program just exit.
if I enable the touch and try to touch the sprite on the screen, the program just crashes and exit.
bool HelloWorld::init()
{
bool bRet = false;
do {
//////////////////////////////
// 1. super init first
// if ( !CCLayer::init() )
// {
// return false;
// }
CC_BREAK_IF(!CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)));
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
/*
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback) );
CC_BREAK_IF(!pCloseItem);
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
CC_BREAK_IF(!pMenu);
this->addChild(pMenu, 1);
*/
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello from AbiTalk", "Arial", 24);
// ask director the window size
CCSize size = CCDirector::sharedDirector()->getWinSize();
// position the label on the center of the screen
pLabel->setPosition( ccp(size.width / 2, size.height - 50) );
// add the label as a child to this layer
this->addChild(pLabel, 1);
CCTextureCache::sharedTextureCache()->addImage("gameImages.pvr.ccz");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("gameImages.plist");
CCAnimation* animation = CCAnimation::animation();
animation->setDelay(0.2f);
char frameName[64];
for(int i = 0; i < 10; i++) {
sprintf(frameName, "bee%d.png", i);
CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName);
animation->addFrame(pFrame);
}
CCAnimate *animate = CCAnimate::actionWithAnimation(animation,true);
CCAction *act = CCRepeatForever::actionWithAction(animate);
// add "HelloWorld" splash screen"
CCSprite *obj = CCSprite::spriteWithFile("bee0.png");
// position the sprite on the center of the screen
obj->setPosition( ccp(size.width/2, size.height/2) );
obj->runAction(act);
obj->setTag(888);
// add the sprite as a child to this layer
this->addChild(obj, 0);
bRet = true;
CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("backgroundmusic.mp3", true);
this->setIsTouchEnabled(true);
} while (0);
return bRet;
}
void HelloWorld::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
}
bool HelloWorld::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
CCPoint touchLocation = touch->locationInView( touch->view() );
touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
if (CCRect::CCRectContainsPoint(obj->boundingBox(), touchLocation))
{// touch b sprite
m_bSpritePressed = true;
}
return true;
}