Simple code works on cocos2d-x but not working on cocos2d-html5

Hi all,

I’m planing to make games with cocos2d-x that works on many platforms so I did some tests,
but I got some problems. I will describe only 2 of them for now.

Please see the code below.

<<Problem 1>>
The close button’s callback doesn’t get called.

<<Problem 2>>
The animation doesn’t work (no error message). It only shows the first png
I did pre-load all the 48 png images.

This code works with cocos2d-x in win32 but not in html5 (I think it should work in iOS/android too, I’ll try)

Can anyone tell me why? Did I miss something?

var MainLayer = cc.Layer.extend({
    init:function () {
        this._super();        
        this.createCloseButton();
        this.createAnimation();
        return true;
    },
    createCloseButton : function(){
        var size = cc.Director.getInstance().getWinSize();
        var closeItem = cc.MenuItemImage.create(
            "res/CloseNormal.png",
            "res/CloseSelected.png",
            function () {
                cc.log('clicked');
            },this);
        closeItem.setAnchorPoint(cc.p(0.5, 0.5));

        var menu = cc.Menu.create(closeItem);
        menu.setPosition(cc.p(0, 0));
        this.addChild(menu, 1);
        closeItem.setPosition(cc.p(size.width - 20, 20));
    },
    createAnimation : function(){
        var size = cc.Director.getInstance().getWinSize();
        var sprite = cc.Sprite.create('res/one_frame1.png');
        sprite.setPosition( cc.p(size.width/4, size.height/2) );
        this.addChild(sprite);

        cc.log('start');
        var animation = cc.Animation.create();
        for (var i=1; i<=48; ++i){
            var path = "res/one_frame"+i+".png";
            animation.addSpriteFrameWithFile( path );
        }
        animation.setLoops(-1);
        animation.setDelayPerUnit(1.0/20.0);
        sprite.runAction(cc.Animate.create(animation));
        cc.log('end');
    }
});

var MainScene = cc.Scene.extend({
    onEnter:function () {
        this._super();
        var layer = new MainLayer();
        layer.init();
        this.addChild(layer);
    }
});

I tested it in firefox/win32 “locally” version 21.0 as well as nightly build.

Thanks,

Kenji Chan

Which version of cocos2d-html5 are you using
are there any errors in console?

Hi,

No error in the console at all.

The version is Cocos2d-html5-v2.1.3.zip

Thanks,

Kenji

I’ve just tested with version 2.1.1, same result

I am getting the error with the animation not playing.

However after tinkering a bit, I found that the animation doesn’t play when loops are set to 1.
I set loops to
1 in the ActionAnimate test in the tests provided with cocos2d-html5-v2.1.5 source and found the same result. The animation would be stuck at the first frame. I tried it for both cases, frames added manually and frames read from file. Same result when loops are set to –1.