import { _decorator, Component,Input,input, EventTouch,Node,Camera, Vec3 } from ‘cc’;
const { ccclass, property } = _decorator;
@ccclass(‘PlayerControl’)
export class PlayerControl extends Component {
start() {
}
protected onLoad(): void {
input.on(Input.EventType.TOUCH_MOVE,this.tMove,this);
}
protected onDestroy(): void {
input.off(Input.EventType.TOUCH_MOVE,this.tMove,this);
}
update(deltaTime: number) {
}
private tMove(eve:EventTouch){
const tVEC2 = eve.getUILocation();
const tp =new Vec3(tVEC2.x,tVEC2.y,0);
this.node.setPosition(tp);
}
}
cocos creater 3.8.5版本
这是代码,主要实现精灵随鼠标按住移动模拟手机触摸动作,发现精灵节点坐标和屏幕坐标不一致导致精灵和鼠标位置错开了,请问大神如何改代码使精灵出现在鼠标位置上?或者实现此功能更优的代码?
