本人cocos2dx用过一些,但是js不是很精通,最近用起了coco2ds js,遇到了不能解释的问题,不知道是js本身的特性,还是我没有使用正确。
现象是这样的:
首先,我定义了一个类叫做mySprite
var mySprite = cc.Sprite.extend({
myType : -1,
init:function (type) {
this._super();
myType = type;
}
})
```
然后在调用的时候发现myType这个属性永远都是-1,下面是调用过程
首先在调用类初始化的时候创建对象
var test = new mySprite();
test.init("mytype");
test.tag = 10001;
this.addChild(test);
```
然后在点击的时候调用对象
var aaa = new mySprite();
aaa = this.getChildByTag(10001);
if (aaa) {
cc.log("test type is " + aaa.myType);
}
else
{
cc.log("not fouond!!!!!");
}
```
到这里我就糊涂了,不知道是为什么出现这个现象,请大家带带菜鸟吧,谢谢大家啦。