Add new file
Name: CMyFirstScene,
Fill in the following content in the. CPP and. h files respectively:
//
// CMyFirstScene.cpp
// linker
//
// Created by HeJiasheng on 14-3-12.
//
//
#include "CMyFirstScene.h"
USING_NS_CC;
Scene* CMyFirstScene::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = CMyFirstScene::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
bool CMyFirstScene::init()
{
if(!CCLayer::init())
{
return false;
}
auto label = LabelTTF::create("New Scene", "Arial", 24);
// position the label on the center of the screen
label->setPosition(Point(200,300));
// add the label as a child to this layer
this->addChild(label, 1);
// do something
return true;
}
#ifndef __linker__CMyFirstScene__
#define __linker__CMyFirstScene__
#include "cocos2d.h"
class CMyFirstScene : public cocos2d::CCLayer
{
public:
static cocos2d::Scene* createScene();
// Initialization
virtual bool init();
CREATE_FUNC(CMyFirstScene);
};
#endif /* defined(__linker__CMyFirstScene__) */
Add the following in the HelloWorld. cpp callback function:
void HelloWorld::imageMenuCallback(Object* pSender)
{
CCLog("ImageMenu");
CCTransitionScene* transiton =CCTransitionProgressRadialCW::create(1.2f, CMyFirstScene::createScene());
CCDirector::sharedDirector()->replaceScene(transiton);
}