这个是我拖动图片的代码,但是为什么报错呢,错误是:Uncaught TypeError: Cannot read property ‘setPosition’ of undefined
plane: null,
isDrag:null,
ctor:function(){
this._super();
//背景
this.setColor(cc.color(126,126,126,126));
//airplane
var size=cc.winSize;
this.plane=new cc.Sprite(res.airPlane);
this.plane.setPosition(cc.p(size.width*0.5,this.plane.getContentSize().height*0.5));
this.addChild(this.plane,1);
this.moveAirPlane();
return true;
}
moveAirPlane: function () {
if(‘mouse’ in cc.sys.capabilities){
cc.eventManager.addListener({
event:cc.EventListener.MOUSE,
onMouseDown: function (event) {
var pos=event.getLocation();
if(event.getButton()==cc.EventMouse.BUTTON_LEFT)
{
cc.log(“left:”+pos.x+"/"+pos.y);
}
else if(event.getButton()==cc.EventMouse.BUTTON_RIGHT)
{
cc.log(“left:”+pos.x+"/"+pos.y);
}
this.isDrag=true;
},
onMouseUp: function (event) {
var pos=event.getLocation();
cc.log(“up:”+pos.x+"/"+pos.y);
this.isDrag=false;
},
onMouseMove: function (event) {
if(this.isDrag==true){
var pos=event.getLocation();
cc.log(“move:”+pos.x+"/"+pos.y);
this.plane.setPosition(pos);
}
}
},this);
}
}