import { GameLogic } from "./update/logic"; const {ccclass, property} = cc._decorator; @ccclass export default class MoveDest extends GameLogic { private _speed: number = 100; public get speed(): number { return this._speed; } public set speed(value: number) { this._speed = value; } private _destination: cc.Vec2 = cc.v2(0, 0); public get destination(): cc.Vec2 { return this._destination; } public set destination(value: cc.Vec2) { this._destination = value; } gameUpdate(dt: number): void { let offset = this.destination.sub(this.node.getPosition()); if(offset.mag() <= this.speed * dt) { this.node.setPosition(this.destination); } else{ let dirction = offset.normalize(); this.node.x += this.speed * dt * dirction.x; this.node.y += this.speed * dt * dirction.y; } } }