I initialize the scene like normal, and after a certain event, the scene’s restart function is called, in that function all objects are removed from the scene, and then the scene’s init function is called again. The objects show up once the game initially starts, but then after it restarts all of the objects are invisible. I know the objects are really there because I tell them to print things when the objects do certain things like collide with each other and it works fine, it’s just that they’re all invisible.
Init function:
bool HelloWorld::init()
{
_scene = this;
GAME_SCENE = this;
//78. 201. 176
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
PAWN = pawn::create();
PAWN->setName("Player");
GAME_GROUND = Ground::create();
HelloWorld::active = true;
this->schedule(HelloWorld::createRocket, 1, "create");
PAWN->setContentSize(Size(50, 50));
PAWN->setPosition(Vec2(Director::getInstance()->getWinSize().width/2, 150));
return true;
}
Restart function:
void HelloWorld::restart() {
this->removeAllChildrenWithCleanup(true);
this->unschedule("create");
HelloWorld::active = false;
this->init();
}
Note: I add the objects to the scene in the objects’ constructor variables. The things that are in all caps are macros for extern variables. I’ve checked to see if the objects were children of the scene by printed this->getChildByName(“Player”)->getName() in the init function and it printed “Player” each time.