Hi,
I created a new project using the cocos2dx v3.7 and tried to play around with the codes a bit.
Here is the code I am playing around:
#include "HelloWorldScene.h"
USING_NS_CC;
Scene* HelloWorldScene::createScene()
{
auto scene = HelloWorldScene::create();
return scene;
}
bool HelloWorldScene::init()
{
if ( !cocos2d::Scene::init() )
return false;
mMainLayer = cocos2d::Layer::create();
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto closeItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorldScene::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height));
auto sprite = Sprite::create("HelloWorld.png");
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
mMainLayer->addChild(label, 1);
mMainLayer->addChild(sprite, 0);
mMainLayer->addChild(menu, 1);
addChild(mMainLayer);
return true;
}
void HelloWorldScene::menuCloseCallback(Ref* pSender)
{
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
I am not a great fan of “HelloWorldScene but inhering to a Layer” right out of the box. So I took a different approach and head on created a scene inhetring from scene and add layers within it if necessary. (Just like the code above). The problem is, this crashes while it doesn’t on my previous project using 3.2.
Please help me to resolve this crash.
Thank you!