cocos2d / cocos2d-js

cocos2d-x for JS
http://www.cocos2d-x.org
MIT License
1.86k stars 490 forks source link

Inconsistent Spine event listeners methods between cocos2d-html5 and cocos2d-x. #1137

Open IgorMats opened 9 years ago

IgorMats commented 9 years ago

Hi.

It seems I found some inconsistent methods:

  1. cocos2d-html5 is have setAnimationListener method of sp.SkeletonAnimation class but on native platforms (e. g. cocos2d-x) it doesn't work.
  2. * cocos2d-x* branch and bindings has a setStartListener and setCompleteListener methods but cocos2d-html5 haven't!

I was very confused when found this issue.

So should I fix it? Thanks.

pandamicro commented 9 years ago

Sorry for the confusion, in fact, we don't have the latest version of Spine in web engine, that's where all these confusion came from. Please be patience, we'd like to upgrade it, but as Spine doesn't have a official js implementation, that will take some effort. To be honest, we don't have man power for it currently

IgorMats commented 9 years ago

Okay, I get it. So maybe I should implement setStartListener and setCompleteListener method in cocos2d-html5 branch for temporarily compatibility?

pandamicro commented 9 years ago

You can try it, I mean I'm not familiar with Spine, but it seems they changed a lot in the new version, so I'm not confident with a simple implementation

IgorMats commented 9 years ago

Here I'm not talking about implementation of all spine API but we can temporarily implement setStartListener and setCompleteListener on javascript level with something like this:

this.setAnimationListener(this, this.onAnimationStateChanged.bind(this));

  /**
   *
   * 
   *
   */
  onAnimationStateChanged: function(target, type, index, event) {
    switch(type) {
      case 0:
      this.onAnimationStart(index);
      break;
      case 1:
      this.onAnimationFinish(index);
      break;
    }
  }

What do you think about this?

Thanks.

pandamicro commented 9 years ago

Yes, of course, our JS level wrapper do exactly this kind of things. Please create a jsb_spine.js file in frameworks/js-bindings/scripts folder and put the wrapper there, you will also need to modify frameworks/js-bindings/scripts/jsb.js to load it when JS engine start up.