• cocos2d-x之 CCSpriteBatchNode 用法总结


    例子1:

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

    • 创建一个CCSpriteBatchNode对象,通过传递一个包含所有spritebatch的名字作为参数,并把它加入到当前场景之中。
    • 接下来,你从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);

  • 相关阅读:
    window常见事件onload
    BOM顶级对象window
    模拟京东快递单号查询案例
    [Hibernate] one-to-one
    Katy Perry
    [Java] int 转换为BigDecimal
    [easyUI] datagrid 数据格 可以进行分页
    [easyUI] 树形菜单 tree
    [easyUI] lazyload 懒加载
    [easyUI] autocomplete 简单自动完成以及ajax从服务器端完成
  • 原文地址:https://www.cnblogs.com/hewei2012/p/3444957.html
Copyright © 2020-2023  润新知