import { _decorator, Component, Input, input, Node,EventTouch } from 'cc';
const { ccclass, property } = _decorator;
start() {
// 输入事件通过接口 input.on(type, callback, target) 注册。TOUCH_START:触摸开始,TOUCH_MOVE:触摸中,TOUCH_END:触摸结束
input.on(Input.EventType.TOUCH_START,this.onTouchStart,this)
input.on(Input.EventType.TOUCH_END,this.onTouchEnd,this)
input.on(Input.EventType.TOUCH_MOVE,this.onTouchMove,this)
}
onTouchStart(event: EventTouch){
console.log('onTouchStart',event.getLocation()) // 触摸位置
}
onTouchEnd(event: EventTouch){
console.log('onTouchEnd',event.getLocation()) // 触摸位置
}
onTouchMove(event: EventTouch){
// 设置相机位置:自身有个node节点,setPosition设置位置,position得到当前位置
// 该值获取到的是像素单位,但是实际移动是米单位,需要对移动位置进行缩放:moveScale
const moveScale = 0.01;
const pos = this.node.position;
this.node.setPosition(pos.x+event.getDeltaX()*moveScale,pos.y+event.getDeltaY()*moveScale,pos.z)
}
07-08
666
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-02