代码简要如下:
//card.js文件中
var Card = cc.Sprite.extend({
//省略代码
});
//cardControl.js文件中
var CardControl = cc.Node.extend({
cards : ],
ctor : function () {
this._super();
for (var i = 0; i < 5; ++i) {
this.cards* = new Card();
this.cards*.attr({x:i*10, y:0, anchorX:0, anchorY:0.5});
this.addChild(this.cards*);
}
},
//后两张牌移动
startOpenAction : function() {
var action = cc.moveBy(1, cc.p(this.OPENCARDLEN, 0));
this.cards.runAction(action);
this.cards.runAction(action.clone());
}
});
//mainlayer.js文件代码
var MainLayer = cc.Layer.extend({
cardControls:],
ctor : function () {
this._super()
var size = cc.winSize;
for (var i = 0; i < 4; ++i) {
this.cardControls.push(new CardControl());
this.cardControls*.tag = i;
this.addChild(this.cardControls*);
}
this.cardControls.attr({x:size.width-330, y:size.height-180});
this.cardControls.attr({x:size.width-330, y:size.height-420});
this.cardControls.attr({x:200, y:size.height-585});
this.cardControls.attr({x:140, y:size.height - 280});
},
touchStartEvent : function (sender, type) {
switch(type) {
case ccui.Widget.TOUCH_ENDED:
var cardCtrl = this.getChildByTag(0);
cardCtrl.startOpenAction();
break;
}
}
});
```
当点击按钮响应touchStartEvent 函数时, cardControl类中的startOpenAction 函数中的this.cards数组竟然始终是cardControls数组的最后一个cardControl成员的this.cards值,
对此例来说就是cardControl.cards的值也就是(cardControl.cards, cardControl.cards, cardControl.cards,始终等于cardControl.cards),但是cardControl类的children里面的值却没有错,求解
*****