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

4.cocos2d-x CCNode_第1张图片



    //遮挡关系
    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);

4.cocos2d-x CCNode_第2张图片


//字体和文本
    //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);

4.cocos2d-x CCNode_第3张图片

你可能感兴趣的:(4.cocos2d-x CCNode)