ctor : function(){
this._super();
var size = cc.winSize;
this.i = 1;
g_LonghuPicLayer = this;
cc.spriteFrameCache.addSpriteFrames(res.Longhu_plist);
cc.spriteFrameCache.addSpriteFrames(res.HistoryMenu_plist);
this.initPic();
this.initWord();
cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: function (touch, event) {
// cc.log("begin");
this.touchLaction = touch.getLocation();
return true;
},
onTouchMoved: function (touch, event) {
// cc.log("move");
},
onTouchEnded: function (touch, event) {
cc.log("end");
var touchEnd = touch.getLocation();
var delat = this.touchLaction.x - touchEnd.x;
//delat取50为边界,确保不会因为误操作而变动;
if (delat >= 50 || delat <= -50){
if (delat < -50){
this.NextPic(); //调用时报错,this.NextPic 不是函数;
cc.log("向右滑动咯");
}
else if (delat >50){
cc.log("向左滑动咯")
}
}
}
}, this);
},
……………………………………省略部分代码………………………………
NextPic : function (){
this.i++;
if (this.i >= 16){
this.i = 1;
}
var pic = "longhu_" + this.i + ".jpg";
this.spritePic.initWithSpriteFrameName(pic);
this.WordLabel.setString(this.str);
},
```
event.getCurrentTarget().NextPic();
listener里面不要使用this, 你可以在外面先定义一个变量 var self = this;
然后里面用self.xxx
谢谢啊,





谢谢,
