testArray = ];
var HelloWorldLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
//////////////////////////////
// 1. super init first
this._super();
for(var i = 0;i<5;i++)
{
var sp = new HeadSprite(“res/CyanSquare.png”);
sp.x = 100 + i100;
sp.y = 200;
this.addChild(sp);
testArray=sp;
}
testArray.haveBetedArray.push(5);
testArray.haveBetedArray.push(6);
testArray.haveBetedArray.push(7);
testArray.num = 12;
var l1 = testArray.haveBetedArray.length;
var l2 = testArray.haveBetedArray.length;
var l3 = testArray.haveBetedArray.length;
for(var j=0;j<testArray.haveBetedArray.length;j++)
{
cc.log("l2 == " + testArray.haveBetedArray );
}
cc.log("l1 == " + l1 + " l2 == " + l2 + " l3 == " + l3);
cc.log(" l1 num == " + testArray.num + " - - l2 num == " + testArray.num);
return true;
}
});
var HeadSprite = cc.Sprite.extend({
haveBetedArray:],
num:0,
ctor:function (arg) {
this._super(arg);
},
});
打印:
cocos2d: JS: l2 == 5
cocos2d: JS: l2 == 6
cocos2d: JS: l2 == 7
cocos2d: JS: l1 == 3 l2 == 3 l3 == 3
cocos2d: JS: l1 num == 12 - - l2 num == 0
我想在 HeadSprite 里添加一个 数组属性 haveBetedArray 然后动态添加元素 不过效果上好像 数组是静态的, 刚接触 cocos2dx js 有人知道 在js 里添加动态数组 怎么实现吗 类似oc 里的 nsarray 和 cocos2dx 里的 ccarray 的结构