[Resolved] Getting Animation Frame

Hey there guys, me again.

I am facing a boring problem… I would like to get in which frame my animation is running, and getting this info I could do some nice stuff.

In reality my code works perfect into HTML5, and it is like this:

this.frameIndex = this.animActions[this.currentState].nextFrame;
But for my happiness it just do NOT work into the JSB, must probably because
nextFrame would be a private (since this things do not exist in HTML5), and it has no permission to get that frame my game do not work.

IMHO it is an error to not have the capacity to get the frame directly, and I found only BAD ways to do it (comparing current frame with all my frame names, and things like that)

Cheers

Hi, JSB doesn’t bind properties of c++ classes.
So _nextFrame doesn’t exist in cc.Animate.
We only expose public member function right now.
If you wish to get the frame index, it could be easily to achieve that by adding a getter function in CCAnimate and re-generate the bindings glue codes.

James Chen wrote:

Hi, JSB doesn’t bind properties of c++ classes.
So _nextFrame doesn’t exist in cc.Animate.
We only expose public member function right now.
If you wish to get the frame index, it could be easily to achieve that by adding a getter function in CCAnimate and re-generate the bindings glue codes.

I understand, and agree. Nevertheless it seems to me that this is an issue. I can change right here in my code, and it will work, for me. But that doesn’t change the fact that this should be added to the Cocos2D-x for everyone.

Again, IMHO, it should be a Getter for the currentFrame or in this case _nextFrame.

Thanks,

Just to keep other interested into this feature in a near future:

I have changed the file CCActionInterval.js and added the code:

getNextFrame: function () {
return this._nextFrame;
},

Then I went to the cocos2d-x and changed the CCActionInterval.h adding:

int getNextFrame();

Into the public: methods. And after that changing CCActionInterval.cpp implementing the method:

int CCAnimate::getNextFrame(){
return m_nNextFrame;
}

(I do believe that a getter could be direct into the header, but I tried it to get a notion how to do a proprer GLUE of the JSB).

Now I am trying to get where exactly is the point of insertion of the jsb_cocos2dx_auto… still have some hard time there.

Hey, please refer to tools/tojs/README.mdown.
After you install the environment of bindings-generator, just go to tools/tojs/README.mdown and execute ./genbindings.sh.
The jsb_cocos2dx_auto.h/.cpp will be auto-generated in scripting/javascript/bindings/generated folder.

James Chen wrote:

Hey, please refer to tools/tojs/README.mdown.
After you install the environment of bindings-generator, just go to tools/tojs/README.mdown and execute ./genbindings.sh.
The jsb_cocos2dx_auto.h/.cpp will be auto-generated in scripting/javascript/bindings/generated folder.

Hey James, thank you for your support! (one of the best always)

Yeah, I found it last night, but I need to leave before I could post here. As you said it is indeed damm easy to glue stuff like that, the README into the tojs is pretty straightforward and I manage to bind it using the genbindings.bat (my environment is Windows). I have tried to run the genbindings.sh with my cygwin, but I could not make it successfully run. Not sure what are the problems and if this is somehow possible to fix.

In order words, if you are using Windows just follow the steps of README.mdown and you will be good to go!

PS: @James Chen, do you think is nice to open an issue and to make a PR with this few changes?

Kind regards,

I have tried to run the genbindings.sh with my cygwin

Yes, genbindings.sh can’t work in cygwin, it could only work under linux and OS X. On windows, you genbindings.bat do the same job. :slight_smile:

PS: @James Chen, do you think is nice to open an issue and to make a PR with this few changes?

Yes, it’s better to send the PR to us. Thanks.

James, I have just sent the PR.
Still need to send the PR into the cocos2d-html5…

Great to know that you too are a Windows user (sometimes is hard to find good dev using win).

It would be great to have the Readme instructions translated into a wiki page here at the site. Along with great information as some of the “travis-scripts” and about the other tools. (Just my 2 cents).