技能开始
This commit is contained in:
49
assets/script/game/skills/BezCom.ts
Normal file
49
assets/script/game/skills/BezCom.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { _decorator, Component, Node, tween, v3, Vec3 } from 'cc';
|
||||
import { SkillCom } from './SkillCom';
|
||||
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)
|
||||
let c_pos = v3((base.t_pos.x+this.node.position.x)/2,this.node.position.y+100)
|
||||
let e_pos = v3(this.node.position.x+base.t_pos.x,this.node.position.y+base.t_pos.y)
|
||||
let time =Math.abs(base.t_pos.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) {
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user