cocos2d-x SpriteBatchNode

来源:互联网 发布:mysql怎么卸载干净 编辑:程序博客网 时间:2024/05/29 18:56
bool SpriteBatchNode::init()
{
Size winSize = Director::sharedDirector()->getWinSize();
Layer::init();

Point ptCenter=ccp(winSize.width/2,winSize.height/2);
/*SpriteBatchNode也是一个容器,但是它只能包容Sprite对象,而且要求这些精灵来自同一个纹理
*/
SpriteBatchNode* batch = SpriteBatchNode::create("CloseNormal.png");
addChild(batch);
Sprite* sprite = Sprite::createWithTexture(batch->getTexture());
batch->addChild(sprite);
_batch = batch;
sprite->setPosition(ptCenter);
setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne);
return true;
}


bool SpriteBatchNode::onTouchBegan(CCTouch* touch,CCEvent* event) {
Size winSize = Director::sharedDirector()->getWinSize();
for (int i = 0; i < 1000;i++) {
Sprite*sprite = Sprite::create("CloseNormal.png");
_batch->addChild(sprite);
sprite->setPosition(ccp(CCRANDOM_0_1()*winSize.width,CCRANDOM_0_1()*winSize.height));
}
return true;
}