1 Star 0 Fork 0

civi/Unistroke-Recognizer-Ts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Test.ts 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
civi 提交于 2022-08-16 14:36 . convert to ts
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);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/civing/Unistroke-Recognizer-Ts.git
git@gitee.com:civing/Unistroke-Recognizer-Ts.git
civing
Unistroke-Recognizer-Ts
Unistroke-Recognizer-Ts
main

搜索帮助