I use a lot of cc.CallFuc.create in my code, It works in HTML5 when crash in jsb;
eg:
var workFinished = cc.CallFunc.create(functino(){cc.log("work Done");}, this); myAnsyncWork(workFinished);
I wrote the code below to callback
_workFinishFunc.execute()
sometime it should be used in cc.Sequence;
jsb crash at the code below:
void CCCallFuncN::execute() { if (m_pCallFuncN) { (m_pSelectorTarget->*m_pCallFuncN)(m_pTarget);// m_pTarget is null ... }
code crash in js wrapper:
void JSCallFuncWrapper::callbackFunc(CCNode *node) const { //node is null ... js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::CCNode>(cx, node); ... }
Should I write my own callback class(in js) for my work?
I appreciate if someone can give me some suggestion.
Why did you invoke *_workFinishFunc.execute()* in JS?
James Chen wrote:
Why did you invoke *workFinishFunc.execute* in JS?
like below:
<pre>
cv.ge.playerReturn = function{
if , player.**baseParam.pos) < cc.POINT_EPSILON
&& player.**sprite.getScale == player.**baseParam.scale){
callFunc.execute;
return;
}
var move = cc.EaseIn.create, 0.5);
var scale = cc.Sequence.create, 0.3),
cc.EaseOut.create, 0.5));
var action = cc.Spawn.create;
player.**sprite.runAction, cc.CallFunc.create{
player._sprite.setZOrder(player.__baseParam.zorder);
},this), callFunc));
}
it should be use like below:
normalAttack:function(target, endCallFun){
if (!target)
target = this.getTargetFormation().findPlayerFromFormationX(this.getFormationX(),
function(player){ return !player.isDie();});
if (!target || target.isDie())
endCallFun.execute();
else
{
cv.ge.playerFlyTo(this, target, cc.CallFunc.create(function(){
target.dealAttacked(this, this.getAttack(), cc.CallFunc.create(function(){
cv.ge.playerReturn(this, endCallFun);
},this))
},this));
}
},
James Chen wrote:
Why did you invoke *_workFinishFunc.execute()* in JS?
Oh, I see.
cc.CallFunc requires target(a CCNode),
it is designed for cocos2dx engine.
May be I have to write my callFunc to replace those I’d wrote in my logic codes.
And wrap it to cc.CallFunc when I pass it as a param to cocos2dx API.
m_pTarget means the target who run the action. If the action didn’t be run, it will be 0.
James Chen wrote:
m_pTarget means the target who run the action. If the action didn’t be run, it will be 0.
thank you very much~
so it work for cocos2dx actions, but not our user-defined logic.
I have my own callfunc class at first.
last night I found that cc.CallFunc had already support what I need, and it works in HTML5, I change all my call back functions to cc.CallFunc.
and now I know what to do.