cocos2d-x基础(四)CCprite CCSpriteBatcNode

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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值