Classes/HelloWorldScene.cpp
// on "init" you need to initialize your instance
on "init" you need to initialize your instance
on " init " you need to initialize your instance
bool HelloWorld::init()
{
    if ( !Scene::init() )
    {
        return false;
    }
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    if (closeItem == nullptr ||
        closeItem->getContentSize().width <= 0 ||
        closeItem->getContentSize().height <= 0)
    {
        problemLoading("'CloseNormal.png' and 'CloseSelected.png'");
    }
    else
    {
        float x = origin.x + visibleSize.width - closeItem->getContentSize().width/2;
        float y = origin.y + closeItem->getContentSize().height/2;
        closeItem->setPosition(Vec2(x,y));
    }
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);
	cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("spritesheet.plist");
	auto backgroundFrame = cache->getSpriteFrameByName("background.png");
	background = Sprite::createWithSpriteFrame(backgroundFrame);
	this->addChild(background);
	background->setPosition(visibleSize / 2);
	initClouds();
	schedule(schedule_selector(HelloWorld::step));
	return true;
}
bool HelloWorld :: init ( ) { if ( ! Scene :: init ( ) ) { return false ; } auto visibleSize = Director :: getInstance ( ) -> getVisibleSize ( ) ; Vec2 origin = Director :: getInstance ( ) -> getVisibleOrigin ( ) ; auto closeItem = MenuItemImage :: create ( " " , " " , CC_CALLBACK_1 ( HelloWorld :: menuCloseCallback , this ) ) ; if ( closeItem == nullptr || closeItem -> getContentSize ( ) . width <= 0 || closeItem -> getContentSize ( ) . height <= 0 ) { problemLoading ( " " ) ; } else { float x = origin . x + visibleSize . width - closeItem -> getContentSize ( ) . width / 2 ; float y = origin . y + closeItem -> getContentSize ( ) . height / 2 ; closeItem -> setPosition ( Vec2 ( x , y ) ) ; } auto menu = Menu :: create ( closeItem , NULL ) ; menu -> setPosition ( Vec2 :: ZERO ) ; this -> addChild ( menu , 1 ) ; cache = SpriteFrameCache :: getInstance ( ) ; cache -> addSpriteFramesWithFile ( " " ) ; auto backgroundFrame = cache -> getSpriteFrameByName ( " " ) ; background = Sprite :: createWithSpriteFrame ( backgroundFrame ) ; this -> addChild ( background ) ; background -> setPosition ( visibleSize / 2 ) ; initClouds ( ) ; schedule ( schedule_selector ( HelloWorld :: step ) ) ; return true ; }
on "init" you need to initialize your instance
on " init " you need to initialize your instance
////////////////////////////// // 1. super init first ///////////////////////////// // 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 // create menu, it's an autorelease object ///////////////////////////// // 3. add your codes below... // Add SpriteSheet with file // Get background from sprite sheet // Initialize the clouds // Start stepping