This repository has been archived by the owner on Nov 14, 2021. It is now read-only.
/
CanvasParticleGenerator.ts
85 lines (72 loc) · 2.18 KB
/
CanvasParticleGenerator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import Container = createjs.Container;
import DisplayObject = createjs.DisplayObject;
import { CanvasParticle } from "./CanvasParticle";
import {
ParticleGenerator,
Particle,
ParticleWay,
ParticleGeneratorOption
} from "particle-waypoint";
export class CanvasParticleGenerator extends ParticleGenerator {
protected parent: Container;
protected map: DisplayObject[]; //パーティクルに使用するテクスチャ配列。ビットマップもしくは描画済みのShapeを利用する。
private mapCounter: number = 0;
private _rangeR: number = 0.0;
private _rangeRotationSpeed: number = 0.0;
constructor(
parent: Container,
path: ParticleWay | ParticleWay[],
map: DisplayObject | DisplayObject[],
option?: CanvasParticleGeneratorOption
) {
super(path, option);
this.parent = parent;
if (option) {
if (option.rangeR) this._rangeR = option.rangeR;
if (option.rangeRotationSpeed)
this._rangeRotationSpeed = option.rangeRotationSpeed;
}
if (Array.isArray(map)) {
if (map.length === 0) {
console.warn(
"CanvasParticleGenerator : オプションとして渡されたDisplayObject配列が空です。このクラスは動作しますが、一切の表示を行いません。"
);
console.trace();
}
this.map = map;
} else {
this.map = [map];
}
}
protected generateParticle(path: ParticleWay): Particle {
const particle = new CanvasParticle(path);
particle.init(
this.parent,
this.map[this.mapCounter],
this._rangeR,
this._rangeRotationSpeed
);
this.mapCounter = (this.mapCounter += 1) % this.map.length;
return particle;
}
public generateAll(): void {
this.mapCounter = 0;
super.generateAll();
}
get rangeRotationSpeed(): number {
return this._rangeRotationSpeed;
}
set rangeRotationSpeed(value: number) {
this._rangeRotationSpeed = value;
}
get rangeR(): number {
return this._rangeR;
}
set rangeR(value: number) {
this._rangeR = value;
}
}
export interface CanvasParticleGeneratorOption extends ParticleGeneratorOption {
rangeR?: number;
rangeRotationSpeed?: number;
}