2018年2月13日
cocos Creator论拖拽的三种方式
日常镇楼图片

第一种-touchmove
程序执行
this.touchPt.on(‘touchmove’, onTouchMove, this.touchPt);
this.touchPt指的是拖拽的物体,(事件监听方式,执行函数,回调函数)
function onTouchMove(touch,event) {
varpt=this.parent.convertTouchToNodeSpaceAR(touch); //转换坐标到局部坐标
this.x=pt.x;
this.y=pt.y;
}
第二种-cc.Node.EventType.TOUCH_MOVE,cc.Node.EventType.TOUCH_END采用节点的方式进行,检测移动,移动结束,代码如下,
varself=this;
letgetTouch=cc.find(‘Canvas/text-Label’);
getTouch.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
this.opacity=100;
vardelta=event.touch.getDelta();
this.x+=delta.x;
this.y+=delta.y;
}, getTouch);
getTouch.on(cc.Node.EventType.TOUCH_END, function () {
this.opacity=255;
}
做了一个物体拖拽时透明的的变化,
第三种-比较随意,可以混搭,即
varself=this;
//拖拽生效代码
functiononTouchMove(touch,event) {
varpt=this.parent.convertTouchToNodeSpaceAR(touch);
this.x=pt.x;
this.y=pt.y;
}
//拖拽物体放置条件
functionendMove(){
this.reactWidthMax=654;this.reactWidthMin=578;this.reactHeightMin=-25;this.reactHeightMax=176;
if(this.y<this.reactHeightMax&&this.y>this.reactHeightMin&&this.x<this.reactWidthMax&&this.x>this.reactWidthMin){
self.jumpStop=cc.audioEngine.playMusic(self.backSound, true, 0.5);
}else{
this.x=this.y=40;
cc.audioEngine.stop(self.jumpStop);
}
}
//拖拽检测状态
this.touchPt.on(‘touchmove’, onTouchMove, this.touchPt); //移动
this.touchPt.on(‘touchend’, endMove, this.touchPt); //移动结束
best anabolic steroid for mass
References:
https://wolfe-forrest-2.mdwrite.net/best-testosterone-booster-expert-recommendations-in-2026
References:
Rocketplay online casino deposit bonuses affiliate program
References:
Lasvegas casino
References:
https://graph.org/Zoome-Casino-Expert-Review-04-20
References:
Casino fandango
References:
https://casino-in-venlo.online-spielhallen.de/
References:
Stuttgart
References:
https://casinos-online-games.online-spielhallen.de/
References:
Rostock
References:
https://online-casinos-mit-lightning-box-einzahlung.online-spielhallen.de/
References:
Deutschland
References:
https://casino-en-online.online-spielhallen.de/
References:
Bear river casino
References:
https://graph.org/How-To-Trigger-Free-Spins-On-Slot-Machines-04-27
References:
Gala casino nottingham
References:
https://i10audio.com/wilhelminay05
References:
Bear river casino nrimatchmaking.com