4.cocos2d-x CCNode

 
    //添加子类函数
    CCLayer *pLayer=CCLayer::create();
    pLayer->setPosition(ccp(240, 240));
    CCSprite *pSprite=CCSprite::create("Icon-72.png");
    pLayer->addChild(pSprite);
    this->addChild(pLayer);
    
    
    CCSprite *pSprite2=CCSprite::create("Icon-72.png");
    pSprite2->setPosition(ccp(100, 100));
    CCLayerColor *pLayerColor=CCLayerColor::create(ccc4(255, 0, 0, 255), 50, 40);
    pSprite2->addChild(pLayerColor);
    this->addChild(pSprite2);



    //遮挡关系
    CCSprite *pSprite1=CCSprite::create("Icon.png");
    pSprite1->setPosition(ccp(150, 200));
    addChild(pSprite1,1);//在上方,不设置默认为0 ,在下方
    
    CCSprite *pSprite2=CCSprite::create("Icon.png");
    pSprite2->setPosition(ccp(100, 200));
    pSprite2->setScale(2);
    addChild(pSprite2);


//字体和文本
    //1.CCLabelTTF 常用的创建方法
    //1.)
    /** creates a CCLabelTTF with a font name and font size in points
     @since v2.0.1
    static CCLabelTTF * create(const char *string, const char *fontName, float fontSize);*/
    

    CCLabelTTF *pLabel=CCLabelTTF::create("myLabel", "Helvetica", 34);
    pLabel->setPosition(ccp(100, 100));
    addChild(pLabel);
    
    //2) create()
    CCLabelTTF *pLabel2=CCLabelTTF::create();
    /*
     CCLabelTTF * CCLabelTTF::create()
     {
     CCLabelTTF * pRet = new CCLabelTTF();
     if (pRet && pRet->init())
     {
     pRet->autorelease();
     }
     else
     {
     CC_SAFE_DELETE(pRet);
     }
     return pRet;
     }
     */
    pLabel2->setString("myLabel2");
    /*
     void CCLabelTTF::setString(const char *string)
     {
     CCAssert(string != NULL, "Invalid string");
     
     if (m_string.compare(string))
     {
     m_string = string;
     
     this->updateTexture();
     }
     }

     */
    pLabel2->setFontSize(34);
    pLabel2->setFontFillColor(ccc3(255, 0, 0));
    pLabel2->setPosition(ccp(100, 200));
    addChild(pLabel2);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值