forked from 4ian/GDevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummyruntimeobject-pixi-renderer.ts
78 lines (65 loc) · 2.18 KB
/
dummyruntimeobject-pixi-renderer.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
namespace gdjs {
/**
* The PIXI.js renderer for the DummyRuntimeObject.
* @ignore
*/
export class DummyRuntimeObjectPixiRenderer {
_object: gdjs.DummyRuntimeObject;
_text: any;
/**
* @param runtimeObject The object to render
* @param instanceContainer The gdjs.RuntimeScene in which the object is
*/
constructor(
runtimeObject: gdjs.DummyRuntimeObject,
instanceContainer: gdjs.RuntimeInstanceContainer
) {
this._object = runtimeObject;
// Keep a reference to the object to read from it later.
// Here we're going to create a dummy text as an example.
if (this._text === undefined) {
this._text = new PIXI.Text(runtimeObject.getText(), { align: 'left' });
}
// You can also create a PIXI sprite or other PIXI object
// this._imageManager = instanceContainer.getGame().getImageManager();
// if ( this._sprite === undefined )
// this._sprite = new PIXI.Sprite(this._imageManager.getInvalidPIXITexture());
this._text.anchor.x = 0.5;
this._text.anchor.y = 0.5;
instanceContainer
.getLayer('')
.getRenderer()
.addRendererObject(this._text, runtimeObject.getZOrder());
this.updatePosition();
}
getRendererObject() {
// Mandatory, return the internal PIXI object used for your object:
return this._text;
}
ensureUpToDate() {
this.updatePosition();
}
updateText(): void {
this._text.text = this._object.getText();
}
updatePosition(): void {
this._text.position.x = this._object.x + this._text.width / 2;
this._text.position.y = this._object.y + this._text.height / 2;
}
updateAngle(): void {
this._text.rotation = gdjs.toRad(this._object.angle);
}
updateOpacity(): void {
this._text.alpha = this._object.opacity / 255;
}
getWidth(): float {
return this._text.width;
}
getHeight(): float {
return this._text.height;
}
}
// Register the class to let the engine use it.
export const DummyRuntimeObjectRenderer = DummyRuntimeObjectPixiRenderer;
export type DummyRuntimeObjectRenderer = DummyRuntimeObjectPixiRenderer;
}