-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.ts
47 lines (39 loc) · 1.18 KB
/
container.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
import * as PIXI from 'pixi.js';
import { Subject } from 'rxjs/internal/Subject';
import { Lifecycle, LifecycleParent, LifecycleProps } from './lifecycle';
export class Container extends PIXI.Container implements LifecycleProps {
/**
* When Lifecycle Object is updated, it emits this subject.
* Along with updating his children, which in turn behave the same.
*/
readonly update$: Subject<number> = new Subject();
/**
* When Lifecycle Object is destroyed, it emits and closes this subject.
* Along with destroying his children, which in turn behave the same.
*/
readonly destroy$: Subject<void> = new Subject();
/**
* Parent GameObject is assigned at creation.
*/
gameObject: LifecycleParent;
/**
* Each Lifecycle Object has label for pixi debugging.
*/
label = 'Container';
constructor(gameObject: LifecycleParent) {
super();
gameObject.addChild(this);
}
/**
* @param deltaTime = 1.0 for 60FPS
*/
update(deltaTime: number): void {
this.x = this.gameObject.x;
this.y = this.gameObject.y;
Lifecycle.update(this, deltaTime);
}
destroy(): void {
super.destroy({ children: true });
Lifecycle.destroy(this);
}
}