HelloWorldScene.cpp
<pre class="cpp" name="code">USING_NS_CC;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
/****************************
* Test
****************************/
static int actionIdx=0;
static std::string effectsList[] =
{
"Shaky3D",
"Waves3D",
"FlipX3D",
"FlipY3D",
"Lens3D",
"Ripple3D",
"Liquid",
"Waves",
"Twirl",
"ShakyTiles3D",
"ShatteredTiles3D",
"ShuffleTiles",
"FadeOutTRTiles",
"FadeOutBLTiles",
"FadeOutUpTiles",
"FadeOutDownTiles",
"TurnOffTiles",
"WavesTiles3D",
"JumpTiles3D",
"SplitRows",
"SplitCols",
"PageTurn3D",
};
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
/****************************
* 绘画矩形
****************************/
CCLayerColor* layercolor = CCLayerColor::create(ccc4(0,0,255,255)); //(红,绿,蓝,0~255 透明到不透明);默认情况,矩形铺满桌面。
//设置矩形大小 CCLayerColor* layercolor = CCLayerColor::create(ccc4(0,0,255,255),100,100);
layercolor->setCascadeColorEnabled(false);
layercolor->setPosition(ccp(0,0));
this->addChild(layercolor,1);
CCLabelTTF* label = CCLabelTTF::create((effectsList[actionIdx]).c_str(), "Marker Felt", 32);
label->setPosition(ccp(visibleSize.width/2,visibleSize.height/2) );
this->addChild(label,1);
CCMenuItemImage *Item = CCMenuItemImage::create("CloseNormal.png","CloseSelected.png",this,menu_selector(HelloWorld::menuItem));
Item->setPosition(ccp(visibleSize.width-Item->getContentSize().width/2,Item->getContentSize().height/2));
CCMenu* pMenu = CCMenu::create(Item,NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu,2);
return true;
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}
/****************************
* Test
****************************/
void HelloWorld::menuItem(CCObject* pSender)
{
actionIdx++;
if(actionIdx>21)
{
actionIdx = 0;
}
init();
}