I’m not familiar with cocos. I would like to create a game logic and I’m stuck with following code. and i need your help.
var fallBounceSeq = cc.sequence(fallTo2, cc.callFunc(function() {
if (!success) {
this.gameOver();
} else {
if(*something true*) {
*add another action*
}
else{
*add another action to sequence*
}
}
},this));
this.square.runAction(fallBounceSeq);
How can i add another action into cc.callFunc()? Should i add another cc.callFunc into if - else condinition?Any suggestions?
igomes
#2
If you prefer to keep your else block, maybe you could try something like the following (written in Notepad, please forgive any mistakes):
const self = this; // not completelly sure what "this" is here.
...
else {
const anotherAction = (someConditionIsTrue) ?
cc.someAction1(...) :
cc.someAction2(...);
self.runAction(anotherAction);
}
If, in the other hand, you prefer another way, you can prepare the array before passing it to the cc.sequence() function. For example:
const callFuncAction = cc.callFunc(() => { ... the code until else ...});
const actions = [fallTo2, callFuncAction];
if (someConditionIsTrue)
actions.push(cc.callFunc(() => { ... something else ... });
else
actions.push(cc.anotherAction);
const fallBounceSeq = cc.sequence(actions);
this.square.runAction(fallBounceSeq);
Hope this helps.
1 Like
system
closed
#3
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.