前几天我在写我的飞机时遇到的一个问题我们的子弹会产生多个,如果要使用我们之前常用的方法我们的程序会被渲染多次
。下面看我们的示例:
他要进行准备,渲染,清除,准备,渲染,清除这个过程进行100次。
使用SpriteBatchNode类渲染 他的工作流程是准备 渲染,渲染…,清除就会提升很高的效率
特别适合用于生成我们的子弹。
大致用法:
Texture2D *texture = TextureCache::sharedTextureCache()->textureForKey("xxx.png");
bulletBatchNode = SpriteBatchNode::createWithTexture(texture);
this->addChild(bulletBatchNode);
Sprite* bullet = Sprite::create("xxx.png");
bullet->setPosition(bulletPosition);
bulletBatchNode->addChild(bullet);
大致实现就是如此。我们通过这个方法进行添加子弹 在我们不需要这个子弹时可以使用bulletBatchNode->remove(bullet);即可是不是挺方便。