and inside gotoMyScene is the same Director::getInstance()->replaceScene(TransitionFade … but it still changes scene without transition, and shows child not found.
Note, that if I replace scene from Keyboard handler, then everything works as expected. What I am doing wrong?
Resolved! The problem was - that I was calling: Director::getInstance()->replaceScene(... multiple times from update(float dt) function. Apparently this is not supported scenario, and care should be taken to not call replaceScene with transition multiple times, without waiting for transition to complete.
Nothing is stopping you from calling replaceScene() from update, but as slackmoehrle pointed out, it will run every frame, so you need to ensure it’s only called once.
For instance:
class YourNode : public cocos2d::Node
{
...
private:
bool enableTransition = false;
};
void YourNode::update(float delta)
{
if (this->enableTransition)
{
this->enableTransition = false;
auto newScene = Scene::create();
Director::getInstance()->replaceScene(newScene);
}
}
So, when you need to do the transition, set the ‘enableTransition’ bool to true, so on the next update it starts the transition, and set ‘enableTransition’ to false, and won’t re-enter that condition.
If you don’t want to wait till the next update to do the transition, then there are other ways to handle this.
Have you put a breakpoint, and made sure the bContact isn’t setting back to true after the update call? …Or put a CCLOG/print and see if it is hitting true on each frame after the only intended one. If so, I like @R101 example of making a unique variable for this, not another variable that may be reset elsewhere.
You may want to put a breakpoint on that, and ensure that kSceneFade is actually still valid at that point. It’s really hard to help you with this, since it’s your code, and it’s really up to you to step through with a debugger to trace down the source of the issue.
That may not be a good idea. Are you 100% certain that mySprite->bContact is not being reset to true, or that mySprite is still valid? If mySprite is freed, but not set to nullptr, then bContact would be a read from a random memory location that may contain different data, and that may make the condition true again. Just throwing ideas out there.
@tdebock pointed out exactly what you should be doing, which is using CCLOG and breakpoints to narrow down your search for the source of the problem.