chapter one

魅力是使用一些特殊的技巧的结果,只是我们大多数人对这些技巧知之甚少,甚至毫不了解。这就是说,魅力是可以学习的。

registerEvent () { let endPoint = cc.v2(0,0) let startPoint = cc.v2(0,0) this.node.on(cc.Node.EventType.TOUCH_MOVE, (e) => { startPoint = e.getStartLocation(); endPoint = e.getLocation(); const distance = startPoint.sub(endPoint).mag(); if (distance <= 300) { this.draw.clear(); this.draw.moveTo(startPoint.x, startPoint.y); this.draw.lineTo(e.getLocationX(), e.getLocationY()); this.draw.stroke(); } }, this); this.node.on(cc.Node.EventType.TOUCH_END, (e) => { this.draw.clear(); let lineStart = startPoint.clone(); // 保存 300 线段的起点 let lineEnd = endPoint.clone(); // 保存 300 线段的终点 this.cut(lineStart, lineEnd); // 在 cut() 方法中处理 300 线段 }, this); } cut(pOne,pTwo){ let ropeJoints: cc.RopeJoint[] = [] if(this.chapterOne.active === true){ //ropeJoints = cc.director.getScene().getComponentsInChildren(cc.RopeJoint); ropeJoints =this.chapterOne.getComponentsInChildren(cc.RopeJoint); } else if(this.chapterTwo.active === true) { //ropeJoints = cc.director.getScene().getComponentsInChildren(cc.RopeJoint); ropeJoints =this.chapterTwo.getComponentsInChildren(cc.RopeJoint); } ropeJoints.forEach((item) => { if(item.node.width ==10&&item.node.height==10){ let lineP1 = pOne; // 线段起点 let lineP2 = pTwo; // 线段终点 let rectPoint = cc.v2(item.node.x-5, item.node.y-5) let rectWorldPoint = item.node.convertToWorldSpaceAR(rectPoint) let rect = cc.rect(rectWorldPoint.x,rectWorldPoint.y, 20, 20); // 矩形,左下角坐标为(5,5),宽高为10 let isIntersect = cc.Intersection.lineRect(lineP1, lineP2, rect); console.log(isIntersect); // 输出 true 或 false if(isIntersect== true){ item.node.parent.active = false } } }); }
05-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值