在3.6.2版本学习B站视频制作打飞机游戏,出现了touch.getDelta返回的Vec2类型没有x属性的情况
this.node.setPosition(pos.x+this.speeddelta.x0.01,pos.y,pos.z)
其中delta是通过const delta = touch.getDelta;获得的Vec2类型变量。但编辑器提示Vec2上不存在属性x
完整代码如下:
import { _decorator, Component, Node, input, EventTouch, Input } from ‘cc’;
const { ccclass, property } = _decorator;
@ccclass(‘plane’)
export class plane extends Component {
@property
public speed = 1;
start() {
input.on(Input.EventType.TOUCH_START, this.onTouchMove, this);
}
update(deltaTime: number) {
}
onTouchMove(event: EventTouch){
const touch = event.touch;
const delta = touch.getDelta;
let pos = this.node.position;
this.node.setPosition(pos.x+this.speed*delta.x*0.01,pos.y,pos.z)
}
}