51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { _decorator, Component, Node, tween, v3, Vec3 } from 'cc';
|
|
import { SkillCom } from './SkillCom';
|
|
import { smc } from '../common/SingletonModuleComp';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('BezCom')
|
|
export class BezCom extends Component {
|
|
start() {
|
|
let base =this.node.getComponent(SkillCom)
|
|
// if(this.node.parent.scale.x < 0){
|
|
// base.t_pos.x=base.t_pos.x*-1
|
|
// }
|
|
let s_pos = v3(this.node.position.x,this.node.position.y+35)
|
|
let c_pos = v3((base.t_pos.x+this.node.position.x)/2,this.node.position.y+200)
|
|
let e_pos = v3(base.t_pos.x,this.node.position.y+50)
|
|
let time =Math.abs(Math.abs(base.t_pos.x-this.node.position.x)/base.speed)
|
|
BezCom.bezierTo(this.node,time,s_pos,c_pos,e_pos,{
|
|
onComplete: (target?: object) => {
|
|
base.is_destroy=true
|
|
},
|
|
}).start();
|
|
}
|
|
|
|
update(deltaTime: number) {
|
|
if(smc.mission.pause) return
|
|
}
|
|
|
|
public static bezierTo(target: any, duration: number, c1: Vec3, c2: Vec3, to: Vec3, opts: any) {
|
|
opts = opts || Object.create(null);
|
|
/*
|
|
* @desc 二阶贝塞尔
|
|
* @param {number} t 当前百分比
|
|
* @param {} p1 起点坐标
|
|
* @param {} cp 控制点
|
|
* @param {} p2 终点坐标
|
|
* @returns {any}
|
|
*/
|
|
let twoBezier = (t:number, p1: Vec3, cp: Vec3, p2: Vec3) => {
|
|
let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
|
|
let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
|
|
return v3(x, y, 0);
|
|
};
|
|
opts.onUpdate = (arg: Vec3, ratio: number) => {
|
|
target.position = twoBezier(ratio, c1, c2, to);
|
|
};
|
|
return tween(target).to(duration, {}, opts);
|
|
}
|
|
}
|
|
|
|
|