| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- cc.Class({
- extends: cc.Component,
- properties: {
- // nodeArr:[cc.Node]
- touchStartPoint: cc.Vec2,
- touchEndPoint: cc.Vec2,
- },
- onLoad() {
- this.node.on(cc.Node.EventType.TOUCH_START, this.ontouch_start, this);
- this.node.on(cc.Node.EventType.TOUCH_END, this.ontouch_End, this);
- this.nodeArr = [];
- },
- ontouch_start(event) {
- // 获取节点坐标
- this.touchStartPoint = event.getLocation();
- },
- //以下部分参考用,具体识别用自己的算法
- ontouch_End(event) {
- this.touchEndPoint = event.getLocation();
- this.calcDir();
- },
- 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 > 15) {
- //console.log("右下滑!");
- this.node.emit("gesture", { name: 'right_down' });
- } else if (dirvecX < -15) {
- // console.log("左下滑!");
- this.node.emit("gesture", { name: 'left_down' });
- } else if (dirvecX <= 15 && dirvecX >= -15) {
- // console.log("向下");
- this.node.emit("gesture", { name: 'down' });
- }
- }
- },
- });
|