我创建了如下的对象池。
void Arrow::CreatePools( cocos2d::Layer *layer )
{
Sprite * sprite;
int i;
//--CREATE ENEMY OBJECT POOL--//
enemyPool = new Vector<Sprite*>(MAX_ENEMY_NUMBER);
enemyIndex = 0;
for (i = 0; i < MAX_ENEMY_NUMBER; i++) {
sprite = Sprite::create("Enemy.png");
sprite->setVisible(false);
layer->addChild(sprite);
enemyPool->pushBack(sprite);
}
当我尝试从池中拉出对象时,cocos 给出了这个错误;{return static_cast<size_type>(this->__end_ - this->__begin_);}
我的对象拉取方法如下。
auto enemy = enemyPool->at(enemyIndex);
enemyIndex++;
if (enemyIndex == enemyPool->size())
enemyIndex = 0;
enemy->stopAllActions();
enemy->setPosition(myStartPoint);
enemy->runAction(myAction);
enemy->setVisible(true);