cocos2d-x之 CCSpriteBatchNode 用法总结

例子1:

    CCSpriteBatchNode* batch = [CCSpriteBatchNode batchNodeWithFile:@"table.png"];
        [self addChild:batch];

  • 创建一个CCSpriteBatchNode对象,通过传递一个包含所有sprite的batch的名字作为参数,并把它加入到当前场景之中。
  • 接下来,你从batch中创建的任何sprite,你应该把它当作CCSpriteBatchNode的一个孩子加进去。只要sprite包含在batch中,那么就没问题,否则会出错。后面加的CCSprite的名字,要不跟 batchNode创建的时候是同一个图片名字,要不就是 CCSpriteFrameCache里面的大图的小图的名字,否则会有问题。其实就是同一个纹理贴图 CCTexture2D  ,比如下面的tabletop.png必须是 table.png的小图。
  •         CCSprite* tableTop = [CCSprite spriteWithSpriteFrameName:@"tabletop.png"];
            tableTop.position = [Helper screenCenter];
            [batch addChild:tableTop];
  • CCSpriteBatchNode可以智能地遍历它的所有的孩子结点,并通过一次OpenGL ES call来渲染这些孩子,而不是以前每个sprite都需要一个OpenGL call,这样渲染速度就会更快。

 例子2:

  CCSpriteBatchNode* batchNode = [CCSpriteBatchNode batchNodeWithFile:@"bullet.png"];  

   [self addChild:batchNode];  

   for (int i = 0; i < 500; ++i)  

   {  

  1.     CCSprite* bullet = [CCSprite spriteWithFile:@"bullet.png"];  
  2.     [batchNode addChild:bullet];  
  3.    }  

 

 

1.  创建  

      CCSpriteBatchNode* create(const char* fileImage, unsigned intcapacity);

 

     CCSpriteBatchNode* create(const char* fileImage);    

   第一个是 传入 文件名,和容量。

   第二个是直接传入文件名,容量是默认的kDefaultSpriteBatchCapacity 值为29

 

   也可以通过  CCSpriteBatchNode* createWithTexture(CCTexture2D* tex,unsigned int capacity);

  

CCSpriteBatchNode* createWithTexture(CCTexture2D* tex);这两个方法传入  CCTexture2D对象来创建。

 

 2.  加入子节点

      virtual void addChild(CCNode * child);

    virtual void addChild(CCNode * child, int zOrder);

    virtual void addChild(CCNode * child, int zOrder, int tag);

 

3.   重新改变zorder

    virtual void reorderChild(CCNode * child, int zOrder);

 

4.  移除

    virtual void removeChild(CCNode* child, bool cleanup);

    virtual void removeAllChildrenWithCleanup(bool cleanup);

转载于:https://www.cnblogs.com/hewei2012/p/3444957.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值