代码拉取完成,页面将自动刷新
同步操作将从 虚幻小黑侠/kele_wxapkg 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
class AwardFlyEffect extends egret.DisplayObjectContainer {
static flyUnitArr: FlyUnit[] = [];
static _targetPostion = {};
static register(id: number, position: { x: number, y: number }) {
this._targetPostion[id] = position;
}
static fly(start: { x: number, y: number }, data: any, end?: { x: number, y: number }, options?: any) {
let awards = data.awards;
if (awards && Array.isArray(awards)) {
for (let i = 0; i < awards.length; i++) {
let award = awards[i];
if (award.id == 1001) {
Game.data["frozenKey"]("coin", BigNum.add(Game.data.coin, award.cnt));
}
if (award.id == 1002) {
Game.data["frozenKey"]("diamond", Game.data.diamond + award.cnt);
}
AwardFlyEffect._fly(start, awards[i], end, options);
}
}
}
static _fly(start: { x: number, y: number }, awards: { id: number, cnt: number }, end?: { x: number, y: number }, options?: any) {
if (!end) {
end = this._targetPostion[awards.id];
}
if (!end) {
console.error("没有目标点...")
return;
}
if (!options) {
options = {};
}
let count = awards.cnt || 1;
let type = options.type || 1;
if (count <= 0) {
egret.error("飞行动画的参数不能小于0");
} else {
count = Math.min(count, 10);
let flyCompleteCount = 0;
let flyCount = count;
while (count--) {
let unit = AwardFlyEffect.flyUnitArr.pop() || new FlyUnit();
let source = awards.id == 1001 ? "main_coin_png" : "main_diamond_png";
unit.setData({ source});
let minAngle = options.minAngle || 30;
let maxAngle = options.maxAngle || 150;
let minDistance = options.minDistance || 50;
let maxDistance = options.maxDistance || 80;
let angle = (minAngle + Math.random() * (maxAngle - minAngle));
let distance = minDistance + Math.random() * (maxDistance - minDistance);
let offX = Math.cos(angle) * distance;
let offY = Math.sin(angle) * distance;
let startOff = new egret.Point(offX, offY);
unit.once("complete", () => {
flyCompleteCount++;
if (flyCompleteCount >= flyCount) {
if (awards.id == 1001) {
Game.data["unFrozenKey"]("coin");
Game.emit("fly_coin_complete");
}
if (awards.id == 1002) {
Game.data["unFrozenKey"]("diamond");
Game.emit("fly_diamond_complete");
}
Game.playSound("getGold");
flyCompleteCount = 0;
}
}, null)
unit.fly(start, end, startOff);
Game.stage.addChild(unit);
}
}
}
}
class FlyUnit extends egret.DisplayObjectContainer {
private image: eui.Image;
private p0_x;
private p0_y;
private p1_x;
private p1_y;
private p2_x;
private p2_y;
public constructor() {
super();
this.image = new eui.Image();
this.image.touchEnabled = false;
this.addChild(this.image);
}
setData(options) {
this.image.source = options.source;
}
public setPos(x: number, y: number) {
this.x = x;
this.y = y;
}
/**
* 飞到目标点
* @param start 开始
* @param end 结束
* @param startOff 开始偏移
*/
public fly(start: { x: number, y: number }, end: { x: number, y: number }, startOff?: { x: number, y: number }) {
this.setPos(start.x, start.y);
let time = MathUtil.between(150, 180);
if (startOff && (startOff.x != start.x || startOff.y != start.y)) {
let tween = egret.Tween.get(this);
let toX = start.x + startOff.x;
let toY = start.y + startOff.y;
tween.to({ x: toX, y: toY }, time, egret.Ease.quartIn).wait(100).call(this.fly1, this, [start, end, startOff]);
} else {
this.fly1(start, end, startOff)
}
}
private fly1(start: { x: number, y: number }, end: { x: number, y: number }, startOff?: { x: number, y: number }) {
let time = (1000 + Math.random() * 500);
this.p0_x = this.x;
this.p0_y = this.y;
let off = this.calcOff(start.x, start.y, end.x, end.y, start.x + startOff.x, start.y + startOff.y);
this.p1_x = off.x;
this.p1_y = off.y;
this.p2_x = end.x;
this.p2_y = end.y;
let tween = egret.Tween.get(this);
tween.to({ factor: 1 }, time, egret.Ease.quadIn).call(this.flyComplete, this);
}
private flyComplete() {
this.dispatchEventWith("complete");
this.release();
AwardFlyEffect.flyUnitArr.push(this);
}
private calcOff(x, y, tx, ty, mx, my) {
var p = [x - tx, y - ty];
var q = [mx - tx, my - ty];
let v = p[0] * q[1] - p[1] * q[0];
let c = [x + (tx - x) * 0.5, y + (ty - y) * 0.5];
let point = new egret.Point();
if (v > 0) {
point.x = Math.min(this.stage.stageWidth - 20, c[0] + Math.max((x - mx) * 3, 200));
point.y = c[1];
} else if (v < 0) {
point.x = Math.max(c[0] + Math.max((x - mx) * 3, -200), 20);
point.y = c[1];
} else {
point.x = tx + mx - x;
point.y = ty + my - y;
}
return point;
}
public get factor(): number {
return 0;
}
//计算方法参考 二次贝塞尔公式
//(1 - t)^2 P0 + 2 t (1 - t) P1 + t^2 P2
public set factor(value: number) {
let t = value;
let p0_x = this.p0_x;
let p0_y = this.p0_y;
let p1_x = this.p1_x;
let p1_y = this.p1_y;
let p2_x = this.p2_x;
let p2_y = this.p2_y;
this.x = (1 - t) * (1 - t) * p0_x + 2 * t * (1 - t) * p1_x + t * t * p2_x;
this.y = (1 - t) * (1 - t) * p0_y + 2 * t * (1 - t) * p1_y + t * t * p2_y;
}
public release() {
DisplayUtil.removeFromParent(this);
egret.Tween.removeTweens(this);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。