JS-Binding AnimationFrame not being created properly

(Using Cocos2D-JS 3.2)
I wanted to test my game on Win32, and noticed animations (flipbook/spritesheet animations) are not working at all. Other actions run fine (moveTo, etc.), but cc.Animation actions seem to do nothing (note, in HTML5, everything works completely fine). So I dug a little further:

I’m creating an AnimationFrame on the Javascript side like this:

//some setup
 for (var i = 0; i < frames.length; ++i)
{
    var frame = frames[i];

    var spriteFrame = new cc.SpriteFrame(imageSource, cc.rect(frame.x, frame.y, frame.w, frame.h));
    var animFrame = new cc.AnimationFrame(spriteFrame, frame.delay);

    animationFrames.push(animFrame);
}

The frames array is just filled with a bunch of {x: …, y:…, w:…, h:…, delay:…} objects that together describe an animation.

I’ve debugged both the C++ and JS side thorougly, but I’ve reached a bitter end. It seems the spriteFrame in the loop is created just fine. Debugging the C++ code, I can see that it properly sets up its arguments (e.g. (24,24) for width and (72,72) for coordinate, when the frame object was {x: 72, y:72, w: 24, h: 24}).

However, upon debugging the C++ code for AnimationFrame (js_cocos2dx_animationframe_constructor), it seems that all it does is create an empty AnimationFrame object (via its default constructor), but then just doesn’t fill it properly with data. All its attributes are their default values (e.g. the _spriteFrame is nullptr).

So all my Javascript side receives is a bunch of AnimationFrames that are invalid. So when I use them to create an animation, it obviously doesn’t work.

Is there anything I can do about this?

In fact, you are missing something in js_cocos2dx_animationframe_constructor, notice the following lines:

if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok)
        ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv);

This actually call the _ctor function with all parameters of the created object, that’s where it suppose to be initialized.

Wait, you are right, we haven’t implement cc.AnimationFrame.prototype._ctor, thank you for reporting this issue. I will defined it in jsb_create_apis.js.

In the meantime, you can directly pass an array of cc.SpriteFrame instead of cc.AnimationFrame to initialize the animation.

It have been fixed in this pull request:

https://github.com/cocos2d/cocos2d-js/pull/1394