当调用moveBy的isDone函数时,如果这个action结束了,那么就会报“Invalid Native Object”错,但是我打了下log,mv仍然是moveBy对象类型且不为空。求大神解惑。
代码如下:
var angle = 30;
var size;
var i = 0;
var mv = null;
var HelloWorldLayer = cc.Layer.extend({
sprite:null,
// mv:null,
ctor:function () {
this._super();
var size = cc.winSize;
var previousP = null;
this.sprite = new cc.Sprite(res.CloseNormal_png);
this.sprite.attr({
x: 0,
y: size.height/2,
anchorX: 0,
anchorY: 0.5
});
this.addChild(this.sprite, 1);
this.scheduleUpdate();
return true;
},
update:function(){
if(mv == null || mv.isDone()){
mv = cc.moveBy(3, cc.p(50,(i%2==0?50:-50)));
this.sprite.runAction(mv);
i++;
}
// if(mv == null){
// mv = cc.moveBy(3, cc.p(50,(i%2==0?50:-50)));
// this.sprite.runAction(mv);
// i++;
// }
// if(mv != null){
// try{
// mv.isDone();
// }catch (e) {
// mv = null;
// }
// }
},
});
var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});
```