For some reason this stopped working. It was working last time I was working on the project, but now it's not. I have double checked that spaceCannonTitle.png
is included in the project. But it's throwing an exception on the setPosition line because title_sprite is null.
bool MenuScene::init()
{
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto title_sprite = cocos2d::Sprite::create( "spaceCannonTitle.png" );
title_sprite->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height - title_sprite->getContentSize( ).height ) );
this->addChild( title_sprite );
...
}
EDIT: If I comment out the title_sprite, then it doesn't crash, but I don't see the menu and I get this error:
libpng error: CgBI: unhandled critical chunk
I found the solution here. Apparently you have to go to Build Settings and set Remove Text Metadata From PNG Files
to NO
.