道岔转动动画

This commit is contained in:
dong 2023-09-28 17:00:17 +08:00
parent 2b31e14d90
commit 8533a71dbc

View File

@ -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 {