Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

Cocos 3.1动画无法移除的问题

$
0
0

@251804974 写道:

我在主线程做一个请求,同时开启一个动画,然后保存这个动画所在的层,和回调,另有一个线程循环获取服务器是否返回,当有返回时,调用performFunctionInCocosThread回到主线程,之后做回调执行和删除这个动画。
但是动画一直在播放,无法移除。之后会有这个提示cocos2d: removeAction: Target not found
我并不知道是不是因为回到主线程这步引发的问题。但是如果我只在主线程里面去做事情,这个错误是不会发生的,动画也可以被移除掉。
代码:
正常调用的代码。fadeout()之后动画可以移除
CommonRequestWait:function(requestfun,responsefun,callFunc) {
if (requestfun) {requestfun();}
var aa = cc.director.getRunningScene()
var connectLayer = CreateConnectLoading(aa);
var func = function()
{
if (responsefun() == false) {
connectLayer.FadeOut();
return;
}
connectLayer.FadeOut();
if (callFunc) {callFunc();}
};
var sequence = cc.sequence
(
cc.delayTime(0.02),
cc.callFunc(func, connectLayer)
);
connectLayer.runAction(sequence.repeatForever());
},

出问题的代码
先从c++那里回到主线程再调用js脚本
Director::getInstance()->getScheduler()->performFunctionInCocosThread([=](){
	ScriptingCore* scrCore = ScriptingCore::getInstance();
	JSContext* jc = scrCore->getGlobalContext();
	jsval owner = OBJECT_TO_JSVAL(scrCore->getGlobalObject());
	jsval codeid;
	codeid = uint32_to_jsval(jc, codeId);
	bool bCodeId = scrCore->executeFunctionWithOwner(owner, "UseCocosThred", 1, &codeid);
});

之后做回调和删除layer及动画的删除操作,这里调用fadeout(),这里的错误信息cocos2d: removeAction: Target not found是发生在打印22222222222之后的。
var CommonServerResponse = function(codeid){
if (!codeid) {return;}
if (CommonServerPush(codeid)){return;}
var info = g_ServerRequestInfo[codeid];
var type = typeof(info);
if (type === "undefined") {
	return;
}
DiyReceiveData(codeid);
var callback = info["callback"];
var protocol = info["protocol"];
var layer = info["layer"];

var Builder = g_ProtoBufBuilder.build(protocol+"Response");
   var protoObj = Builder.decode(g_SerProBuf);
layer.FadeOut(layer);
cc.log("11111111111111111="+protoObj.errno);
if(!UIUtils.CommonErrorTipsShow(protoObj.errno,"")){return;}
if (callback) {callback(protoObj);}
cc.log("2222222222222222222");
};

请求部分代码
CommonRequest:function(requestfun,codeid,protocol,callFunc){
    var connectLayer = CreateConnectLoading(cc.director.getRunningScene());
    CommonServerRequest(requestfun,codeid,protocol,callFunc,connectLayer);
},

var g_ServerRequestInfo = [];
//通用数据请求
var CommonServerRequest = function(request_func,codeid,protocol,callback,layer){
var info = [];
info["protocol"] = protocol;
info["callback"] = callback;
info["layer"] = layer;
g_ServerRequestInfo[codeid] = info;
if (request_func) {
	request_func();
}

};

帖子: 2

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>