| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- cc.Class({
- extends: cc.Component,
- properties: {
- // nodeArr:[cc.Node]
- touchStartPoint: cc.Vec2,
- touchEndPoint: cc.Vec2,
- },
- onLoad() {
- this.GameMode = cc.find("GameMode").getComponent("GameMode");
- this.touch_defance = cc.find("")
- this.nodeArr = [];
- },
- ontouch_start(event) {
- // 获取节点坐标
- this.touchStartPoint = event.getLocation();
- },
- //以下部分参考用,具体识别用自己的算法
- ontouch_End(event) {
- this.touchEndPoint = event.getLocation();
- this.calcDir();
- },
- update(dt) {
- this.scheduleOnce(function() {
- if (this.GameMode._gamestart) {
- this.node.on(cc.Node.EventType.TOUCH_START, this.ontouch_start, this);
- this.node.on(cc.Node.EventType.TOUCH_END, this.ontouch_End, this);
- }
- }, 4);
- },
- calcDir: function() {
- let dirvecX = this.touchEndPoint.x - this.touchStartPoint.x;
- let dirvecY = this.touchEndPoint.y - this.touchStartPoint.y;
- if (dirvecY > 0) {
- if (dirvecX > 0) {
- //向右 上 出左拳
- //console.log("右上滑!");
- this.node.emit("gesture", { name: 'right_top' });
- } else if (dirvecX < 0) {
- //向左上 出右拳
- //console.log("左上滑!");
- this.node.emit("gesture", { name: 'left_top' });
- }
- } else if (dirvecY < 0) {
- if (dirvecX > 0) {
- //console.log("右下滑!");
- this.node.emit("gesture", { name: 'right_down' });
- } else if (dirvecX < 0) {
- // console.log("左下滑!");
- this.node.emit("gesture", { name: 'left_down' });
- }
- }
- },
- btn_touch(event) {
- if (event.target.name == "Circle") {
- if (this.GameMode._gamestart) {
- this.node.emit("gesture", { name: 'down' });
- }
- }
- },
- });
|