From 8533a71dbcf1b4bba6001e9026d835b3b3859cff Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Thu, 28 Sep 2023 17:00:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=93=E5=B2=94=E8=BD=AC=E5=8A=A8=E5=8A=A8?= =?UTF-8?q?=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/turnout/Turnout.ts | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/graphics/turnout/Turnout.ts b/src/graphics/turnout/Turnout.ts index dc671ee..7cf0924 100644 --- a/src/graphics/turnout/Turnout.ts +++ b/src/graphics/turnout/Turnout.ts @@ -1,5 +1,6 @@ import { Graphics, IPointData } from 'pixi.js'; import { + GraphicAnimation, GraphicData, GraphicRelationParam, GraphicState, @@ -146,6 +147,7 @@ export class Turnout extends JlGraphic { sections: [TurnoutSection, TurnoutSection, TurnoutSection]; label: VectorText; }; + deltaTime: number; constructor() { super(Turnout.Type); @@ -159,6 +161,7 @@ export class Turnout extends JlGraphic { ], label: new VectorText(), }; + this.deltaTime = 0; this.addChild(this.graphics.fork); // this.addChild(...this.graphics.sections); this.addChild(this.graphics.sections[0]); @@ -195,14 +198,46 @@ export class Turnout extends JlGraphic { if (this.states.normal) { this.graphics.fork.paint(pointB[0]); this.graphics.label.style.stroke = TurnoutConsts.normalLabelColor; + this.graphics.fork.visible = true; } else if (this.states.reverse) { this.graphics.fork.paint(pointC[0]); this.graphics.label.style.stroke = TurnoutConsts.reverseLabelColor; + this.graphics.fork.visible = true; } this.graphics.sections.forEach((sectionGraphic) => sectionGraphic.paint()); this.graphics.label.text = this.datas.code; + if (this.states.turning) { + this.initTurnoutTurning(); + } else { + this.stopTurnoutTurning(); + } + } + initTurnoutTurning() { + // 道岔转动 + const name = 'turnout_turning'; + let turnoutTurning = this.animation(name); + if (!turnoutTurning) { + turnoutTurning = GraphicAnimation.init({ + name: 'turnout_turning', + run: (dt: number) => { + this.deltaTime += dt; + this.deltaTime = this.deltaTime % 60; + this.graphics.fork.visible = this.deltaTime > 30; + }, + }); + this.addAnimation(turnoutTurning); + } + turnoutTurning.resume(); + } + stopTurnoutTurning() { + const name = 'turnout_turning'; + const turnoutTurning = this.animation(name); + if (turnoutTurning) { + turnoutTurning.pause(); + this.deltaTime = 0; + } } buildRelation(): void {