void switchResources(cocos2d::Ref* loading, std::vector<std::string>& toLoadRes, std::vector<std::string> toReleaseRes, std::function<cocos2d::Scene*()> sceneGenFunc, int delayTime /*= 0*/, std::function<void(std::function<void()>&&)> beforeCallback, std::function<void()> afterCallback)
{
    auto toSceneFunc = [=](){
        loading->release();
        if (loading->getReferenceCount() <= 1) {
            auto scene = sceneGenFunc();
            cocos2d::Director::getInstance()->replaceScene(scene);
            /*release previos resources*/
            releaseAllResources(toReleaseRes);
            if(afterCallback) afterCallback();
        }
    };
    loading->retain();
    loadAllResourcesAsyc(toLoadRes, [=](int progress){
        cocos2d::log("load progress: %d", progress);
        if (progress == 0) {
            toSceneFunc();
        }
    });
    if (delayTime > 0) {
        loading->retain();
        minLoadingTime(toSceneFunc, delayTime);
    }
    if (beforeCallback) {
        /*自己retain loading!!!*/
        beforeCallback(toSceneFunc);
    }
}
Example #2
0
// Sets a value of the object to string
int UIOperationEvent::setString(const char* pString)
{
	if (stringValue)
		releaseAllResources();
	stringValue = (char*) allocateResource (sizeof (char), (int)strlen(pString) + 1);
	if (!stringValue)
	{
		valueType = UI_STRING;
		return setError(ERR_MEMORY_ALLOC, SETTING_OPERATION_EVENT);
	}
	strcpy (stringValue, pString);
	length = (int)strlen(stringValue);
	set_value();
	return setSuccess();
}
Example #3
0
void UIOperationEvent::resetEvent(bool withStop)
{
	releaseAllResources();
	OperationEvent::resetEvent(withStop);
}