I use cocs2d-x There is a scene-selector of levels lvlSel . There is a scene with a basic set of level lvl . There is a loadLevel(int ID) function for drawing a level from the lvl_ID file. There is a function initScene(int lvlswitch) , which switches scenes via replaceScene (). The problem is that I cannot call loadLevel with the desired parameter after initializing a new scene. If I use rendering inside initialization, I can not pass the necessary parameter for loadLevel() . How can I call this function after scene initialization?

    1 answer 1

    To be honest, the question is not entirely clear, but you can always inherit from who implements these functions, and change the structure and replaceScene () and all the rest. You can also make a static class, or a global variable (at worst) that will store the desired parameter.

    • loadLevel is a custom function with a parameter that loads the graphics of a particular level (the same parameter) onto the Level stage. initScenes is also a custom function. Invokes a specific scene also through a parameter. - Sugar Sugar
    • Hang the stage in the Internet object - a timer. Since this is coco2dx, use schedule (schedule_selector (Object :: tick)); So you can call anything. I make a guess. Actually, I’m probably stupid, but I don’t quite understand the situation. - Define
    • The header file describes the scene class, its initializer Level :: init () and additional functions, if necessary. In my case - loading graphics and loading UI. The UI for all levels is the same, so that the parameters are not needed and it is quietly called from the scene initializer. But the levels themselves are different and cannot be called inside the initializer without passing a parameter. In .cpp, the base scene () function is first described, and then the initializer is started. replaceScene uses scene () to change the scene, and that one already calls the initializer. - Sugar Sugar
    • but how do I pass a parameter to the called function? I can safely write it there without a timer. It will work, only all the levels will be the same for me, because ID card does not change - Sugar
    • void CCDirector :: replaceScene (CCScene * pScene) {CCAssert (pScene! = NULL, "the scene should not be null"); unsigned int index = m_pobScenesStack-> count (); m_bSendCleanupToScene = true; m_pobScenesStack-> replaceObjectAtIndex (index - 1, pScene); m_pNextScene = pScene; } Should this function pass a parameter? Create a Class add-on over the director, and call replaceScene (int myID), which calls loadLevel (int ID) after initializing the scene. - Define