how to init ClassA(inherite from Sprite) use SpriteBatchNode
- i have a class
class ClassA :public cocos2d::Sprite
{
public:
float speedX;
*
} - i add many ClassA to screen, i find it use many memory/time, so i want to use SpriteBatchNode.
but i find SpriteBatchNode, which is initWithFile (const char *fileImage, int capacity).
how to init with ClassA??
fix it:
1.
bool ClassA::init()
{
if ( !Sprite::init() )
{
return false;
}
if (this~~>texture != NULL)
{
//this~~>createWithTexture(this~~>texture);
this~~>initWithTexture(this~~>texture);
//this~~>setDisplayFrame(this~~>texture);
//CCLOG;
}
}
2. use:
SpriteBatchNode* batchNode = SpriteBatchNode::create;
this~~>addChild(batchNode);
Size s = Director::getInstance()>getVisibleSize;>autorelease(); // public Cocos2d::Sprite 公共继承才行
for
{
float x = CCRANDOM_0_1*s.width;
float y = CCRANDOM_0_1s.height;
ClassAo = new ClassA, x, y);
if )
{
o
}
batchNode->addChild((Node *)o);
}