init方法代码进行了整理(自备)

        自己进行整理,直接可复制粘贴使用的代码,非常基础的东西,如果刚入门的朋友可能会觉得cocos2d-x中HelloWorld中init方法虽然很全但是够乱,看不明白,下面奉上代码。
bool start::init()
{
    bool bRet = false;
    do 
    {
      

        CC_BREAK_IF(! CCLayer::init());
       
//----------------------获得屏幕的大小-----------------------------------
        CCSize size = CCDirector::sharedDirector()->getWinSize();

//----------------------屏幕中显示字体-----------------------------------
        CCLabelTTF* pLabel = CCLabelTTF::create("", "Arial", 24);
        CC_BREAK_IF(! pLabel);
        pLabel->setPosition(ccp(size.width / 2, size.height - 50));
        this->addChild(pLabel, 1);

//----------------------第一层图片----------------------------------------
        CCSprite* pSprite = CCSprite::create("HelloWorld.png");
        CC_BREAK_IF(! pSprite);
        pSprite->setPosition(ccp(size.width/2, size.height/2));
		this->addChild(pSprite, 0);

//---------------------添加一个就这么简单-------------------------------
        CCSprite* pSprite02 = CCSprite::create("HelloWorld02.png");
		 CC_BREAK_IF(! pSprite02);
        pSprite02->setPosition(ccp(size.width/2, size.height/2));
        this->addChild(pSprite02,2);	
//---------------------------------------------------------------------
        bRet = true;

    } while (0);

    return bRet;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值