//place it after USING_NS_CC;
//init static variable
int HelloWorld::calendarNum = 0;
Scene* HelloWorld::sceneWithLastCalendar(int lastCalendar)
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = HelloWorld::layerWithLastCalendar(lastCalendar);
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// Add an another create methond
Layer* HelloWorld::layerWithLastCalendar(int lastCalendar)
{
HelloWorld *pRet = new HelloWorld();
if (pRet && pRet->init())
{
pRet->autorelease();
Size winSize = Director::getInstance()->getWinSize();
do {
calendarNum = (arc4random() % 3) + 1;
} while (calendarNum == lastCalendar);
char spriteName[100] = {0};
sprintf(spriteName, "Calendar%d.png", calendarNum);
Sprite * cal = Sprite::create(spriteName);
cal->setPosition(winSize.width/2, winSize.height/2);
pRet->addChild(cal);
return pRet;
}
else
{
delete pRet;
pRet = NULL;
return NULL;
}
}