代码拉取完成,页面将自动刷新
import { _decorator, Component, Node, EventTouch, log } from 'cc';
import { DollarRecognizer, Point } from './dollar';
const { ccclass, property } = _decorator;
@ccclass('Test')
export class Test extends Component {
private _gesture: any = null;
private _gesturePoints: any = [];
start(): void {
this.startListener();
}
destory(): void {
this.endListener();
}
startListener() {
this.node.on(Node.EventType.TOUCH_START, this.touchStart, this);
this.node.on(Node.EventType.TOUCH_MOVE, this.touchMove, this);
this.node.on(Node.EventType.TOUCH_END, this.touchEnd, this);
this.node.on(Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
}
endListener() {
this.node.off(Node.EventType.TOUCH_START, this.touchStart, this);
this.node.off(Node.EventType.TOUCH_MOVE, this.touchMove, this);
this.node.off(Node.EventType.TOUCH_END, this.touchEnd, this);
this.node.off(Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
}
touchStart(e: EventTouch) {
this._gesture = new DollarRecognizer();
this._gesturePoints = [];
}
touchMove(e: EventTouch) {
let location = e.getUILocation();
this._gesturePoints.push(new Point(-location.x, location.y));
}
touchEnd(e: EventTouch) {
let result = this._gesture.Recognize(this._gesturePoints);
this._gesture = null;
this._gesturePoints = [];
log(result.name, result.score, result.time);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。