A friends and me are developing a game for Iphone with cocos2dx. It is simple, the tipical runner in a infinite map with random obstacles.
The map is charged in chuncks, all of this initializated with random structures, when the position of the player is in the end of the chunck add the next chunck, and if the player is in the start of the chunck remove the chunck passed.
In the scene, I have a listener called by this way:
//For remove a chunck from the view
unsigned int id = this->getChunckForRemove();
this->_listener->removeChunckFromScene(id);
....
//For add a chunck to the view
TiledMap::Chunck* chunck = new TiledMap::Chunck(this.globalPosition);
this->globalPosition += SIZE_OF_CHUNCK; //Ex.: SIZE_OF_CHUNCK = 5194
this->_listener->addChunckToScene(chunck, 1);
The implemenentation is the scene, and it the next:
void
Scenes::
PlayerTestScene::removeChunckFromScene(const int id)
{
log("Remove chunck from scene :%d", id);
this->_nodeScroll->removeChildByTag(id);
}
...
void
Scenes::
PlayerTestScene::addChunckToScene(const int id, TiledMap::Chunck* chunck)
{
log("Add chunck to scene :%d", id);
this->_nodeScroll->addChild(chunck->_node, 1, id);
this->player->setFloorCollision(chunck->_collisionables);
}
The structure Chunck is the next:
class Chunck {
Node* _node;
std::vector<BlockCollisionable> _collisionables;
....
Chunck() {
_node = Node::create();
_node->retain();
}
~Chunck() {
_node->autorelease();
}
}
The problem is when I add the chunck, I have no problem in the logs but it not drawed. The screen in these position are black, I don't undertand what it is hapening.
In addition, When I remove the last chunck fail with this error:
Assert failed: reference count should be greater than 0 Assertion failed: (_referenceCount > 0), function release, file /.../cocos2d/cocos/base/CCRef.cpp, line 98.
Thanks :D