cocos2d-x基础(四)CCprite CCSpriteBatcNode

来源:互联网 发布:网络兼职qq群 编辑:程序博客网 时间:2024/06/06 04:57

CCSprite:

        CCSpriteFrameCache::sharedSpriteFrameCache();

       CCSpriteFrameCache *pCache=CCSpriteFrameCache::sharedSpriteFrameCache();
       pCache->addSpriteFrame(CCSpriteFrame::create("button.png",CCRectMake(0, 0, 64, 64)),"button.png");

             pPoint->setDisplayFrame(pCache->spriteFrameByName("button.png"));    //将加入缓存的SpriteFrame显示出来,其中”button“已经在前面 加入缓存了


CCSpriteBatchNode:

(1)SpriteBatchNode就像是一个批节点:如果它包含孩子,它会一次性绘制所有孩子。

(2)SpriteBatchNode可以应用一个且只有一个纹理图集(TextureAtlas)

  例子:

          加入一只熊

             CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Bear.plist","Bear.png");  //现将plist文件加入缓存
              CCSpriteBatchNode *pSpriteBatchNode=CCSpriteBatchNode::create("Bear.png",8);           //创建batchNode,一个纹理图集,8个子节点
              CCSprite *pBear_1=CCSprite::createWithSpriteFrameName("bear1.png");                      //通过加入缓存的plist文件创建精灵,并且该精灵的纹理必须在BathcNode的纹理图集中,否则在pSpriteBatchNode->addChild(pBear_1);//会出现错误
             pBear_1->setPosition(ccp(size.width/2,size.height/2));
             pSpriteBatchNode->addChild(pBear_1);
             this->addChild(pSpriteBatchNode);





0 0
原创粉丝点击