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