Skip to content

Commit a8a2d80

Browse files
committed
💄 优化节点创建特效,之前的太浮夸了
1 parent 7c2ca53 commit a8a2d80

File tree

2 files changed

+137
-37
lines changed

2 files changed

+137
-37
lines changed

src/core/service/effectEngine/concrete/EntityCreateLineEffect.tsx

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Rectangle } from "../../../dataStruct/shape/Rectangle";
44
import { Vector } from "../../../dataStruct/Vector";
55
import { StageStyleManager } from "../../stageStyle/StageStyleManager";
66
import { EffectObject } from "../effectObject";
7-
import { ZapLineEffect } from "./ZapLineEffect";
7+
import { TechLineEffect } from "./TechLineEffect";
88

99
export class EntityCreateLineEffect extends EffectObject {
1010
constructor(
@@ -14,85 +14,87 @@ export class EntityCreateLineEffect extends EffectObject {
1414
super(timeProgress);
1515
// 子特效
1616
this.subEffects = [];
17+
const initLen = 20;
18+
const segmentCount = 50;
19+
const preChange = -1;
20+
// const effectColor = StageStyleManager.currentStyle.CollideBoxSelectedColor;
21+
const effectColor = StageStyleManager.currentStyle.StageObjectBorderColor;
22+
const rotateDegrees = 90;
1723
// 顶部线
18-
for (let i = 0; i < 10; i++) {
24+
for (let i = 0; i < 5; i++) {
1925
const topStartLocation = new Vector(
2026
Random.randomFloat(this.rect.left, this.rect.right),
2127
this.rect.top,
2228
);
23-
const topEndLocation = topStartLocation.add(
24-
topStartLocation.subtract(this.rect.center).multiply(100),
25-
);
26-
const zapLineEffect = new ZapLineEffect(
29+
const topEndLocation = topStartLocation.add(new Vector(0, -1000));
30+
const zapLineEffect = new TechLineEffect(
2731
topStartLocation,
2832
topEndLocation,
29-
50,
30-
20,
31-
45,
32-
StageStyleManager.currentStyle.StageObjectBorderColor,
33+
segmentCount,
34+
initLen,
35+
preChange,
36+
rotateDegrees,
37+
effectColor,
3338
this.timeProgress.clone(),
3439
2,
3540
);
3641
this.subEffects.push(zapLineEffect);
3742
}
3843
// 底部线
39-
for (let i = 0; i < 10; i++) {
44+
for (let i = 0; i < 5; i++) {
4045
const bottomStartLocation = new Vector(
4146
Random.randomFloat(this.rect.left, this.rect.right),
4247
this.rect.bottom,
4348
);
44-
const bottomEndLocation = bottomStartLocation.add(
45-
bottomStartLocation.subtract(this.rect.center).multiply(100),
46-
);
47-
const zapLineEffect = new ZapLineEffect(
49+
const bottomEndLocation = bottomStartLocation.add(new Vector(0, 1000));
50+
const zapLineEffect = new TechLineEffect(
4851
bottomStartLocation,
4952
bottomEndLocation,
50-
50,
51-
20,
52-
45,
53-
StageStyleManager.currentStyle.StageObjectBorderColor,
53+
segmentCount,
54+
initLen,
55+
preChange,
56+
rotateDegrees,
57+
effectColor,
5458
this.timeProgress.clone(),
5559
2,
5660
);
5761
this.subEffects.push(zapLineEffect);
5862
}
5963
// 左侧线
60-
for (let i = 0; i < 10; i++) {
64+
for (let i = 0; i < 5; i++) {
6165
const leftStartLocation = new Vector(
6266
this.rect.left,
6367
Random.randomFloat(this.rect.top, this.rect.bottom),
6468
);
65-
const leftEndLocation = leftStartLocation.add(
66-
leftStartLocation.subtract(this.rect.center).multiply(100),
67-
);
68-
const zapLineEffect = new ZapLineEffect(
69+
const leftEndLocation = leftStartLocation.add(new Vector(-1000, 0));
70+
const zapLineEffect = new TechLineEffect(
6971
leftStartLocation,
7072
leftEndLocation,
71-
50,
72-
20,
73-
45,
74-
StageStyleManager.currentStyle.StageObjectBorderColor,
73+
segmentCount,
74+
initLen,
75+
preChange,
76+
rotateDegrees,
77+
effectColor,
7578
this.timeProgress.clone(),
7679
2,
7780
);
7881
this.subEffects.push(zapLineEffect);
7982
}
8083
// 右侧线
81-
for (let i = 0; i < 10; i++) {
84+
for (let i = 0; i < 5; i++) {
8285
const rightStartLocation = new Vector(
8386
this.rect.right,
8487
Random.randomFloat(this.rect.top, this.rect.bottom),
8588
);
86-
const rightEndLocation = rightStartLocation.add(
87-
rightStartLocation.subtract(this.rect.center).multiply(100),
88-
);
89-
const zapLineEffect = new ZapLineEffect(
89+
const rightEndLocation = rightStartLocation.add(new Vector(1000, 0));
90+
const zapLineEffect = new TechLineEffect(
9091
rightStartLocation,
9192
rightEndLocation,
92-
50,
93-
20,
94-
45,
95-
StageStyleManager.currentStyle.StageObjectBorderColor,
93+
segmentCount,
94+
initLen,
95+
preChange,
96+
rotateDegrees,
97+
effectColor,
9698
this.timeProgress.clone(),
9799
2,
98100
);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { Random } from "../../../algorithm/random";
2+
import { Color, mixColors } from "../../../dataStruct/Color";
3+
import { ProgressNumber } from "../../../dataStruct/ProgressNumber";
4+
import { Vector } from "../../../dataStruct/Vector";
5+
import { CurveRenderer } from "../../../render/canvas2d/basicRenderer/curveRenderer";
6+
import { Renderer } from "../../../render/canvas2d/renderer";
7+
import { Camera } from "../../../stage/Camera";
8+
import { EffectObject } from "../effectObject";
9+
10+
/**
11+
* 一条富有科技感的连线特效
12+
* 从start点开始,朝着end点前进,
13+
* 经过segmentCount短折线,每段折线的长度为initLen,每次偏转角度为-rotateDegrees | 0 | rotateDegrees 之间随机
14+
* 最终不一定到达end点,因为有随机偏移
15+
*/
16+
export class TechLineEffect extends EffectObject {
17+
constructor(
18+
start: Vector,
19+
private end: Vector,
20+
private segmentCount: number,
21+
private initLen: number,
22+
private lenPreChange: number,
23+
private maxRotateDegrees: number,
24+
private color: Color,
25+
public timeProgress: ProgressNumber,
26+
private lineWidth = 10,
27+
) {
28+
super(timeProgress);
29+
this.end = end;
30+
this.segmentCount = segmentCount;
31+
this.initLen = initLen;
32+
this.lenPreChange = lenPreChange;
33+
this.maxRotateDegrees = maxRotateDegrees;
34+
this.currentPoints.push(start);
35+
}
36+
37+
/**
38+
* 记录所有走过的折线点
39+
*/
40+
private currentPoints: Vector[] = [];
41+
42+
private currentLen = this.initLen;
43+
44+
tick(): void {
45+
super.tick();
46+
if (this.currentPoints.length < this.segmentCount + 1) {
47+
// 开始增加点
48+
const lastPoint = this.currentPoints[this.currentPoints.length - 1];
49+
const direction = Vector.fromTwoPoints(lastPoint, this.end).normalize();
50+
const randomDegrees = Random.randomItem([
51+
-this.maxRotateDegrees,
52+
0,
53+
this.maxRotateDegrees,
54+
]);
55+
const newLocation = lastPoint.add(
56+
direction.rotateDegrees(randomDegrees).multiply(this.currentLen),
57+
);
58+
this.currentPoints.push(newLocation);
59+
// 更新长度
60+
this.currentLen += this.lenPreChange;
61+
}
62+
}
63+
64+
static normal(
65+
startLocation: Vector,
66+
endLocation: Vector,
67+
color: Color,
68+
): TechLineEffect {
69+
return new TechLineEffect(
70+
startLocation,
71+
endLocation,
72+
10,
73+
100,
74+
-5,
75+
15,
76+
color,
77+
new ProgressNumber(0, 50),
78+
);
79+
}
80+
81+
render(): void {
82+
const currentColor = mixColors(
83+
this.color,
84+
Color.Transparent,
85+
this.timeProgress.rate,
86+
);
87+
const viewLocations = this.currentPoints.map((p) =>
88+
Renderer.transformWorld2View(p),
89+
);
90+
CurveRenderer.renderSolidLineMultipleWithShadow(
91+
viewLocations,
92+
currentColor,
93+
(1 - this.timeProgress.rate) * this.lineWidth * Camera.currentScale,
94+
this.color,
95+
10,
96+
);
97+
}
98+
}

0 commit comments

Comments
 (0)