Re run same function?

Re run same function?
0.0 0


Hello, I’m using cocos2d-x-3.0rc0.

I’m creating a loading scene and I’m trying looping a function that precaches all my files and updates my progress bar after each precache. Therefore I need to call the function again and again but If I do that directly the application crashes when I try to replace scene.

Assert failed: Use runWithScene: instead to start the director
Assertion failed: (_runningScene)

However I came up with the solution that I should schedule a new function and call the other function from there.
So what I am doing now is:

this->schedule(schedule_selector(LoadingScene::keepLoading), 0.00f);

void LoadingScene::keepLoading(float dt)

But I need a more efficient solution than this. Any ideas?


There is a test case named TextureCacheTest in cpp-tests. You can take a look at it. It’s using async loading methods in TextureCache.

By now, only image files can be loaded by method TextureCache::addImageAsync().
Hope it’s helpful.


Thanks, the test case in cpp-tests is very useful to me.You may use it like this:
CCTextureCache::sharedTextureCache()->addImageAsync("gmbg/longding.png",CC_CALLBACK_1(LoadingLayer::loadCallBack, this));
different from the previous version:
CCTextureCache::sharedTextureCache()->addImageAsync("gmbg/longding.png", this, callfuncO_selector(LoadingLayer::loadCallBack));