6.【cocos2d-x-2.2.3】数字切换

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();
}
 
 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值