forked from 4ian/GDevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdummyruntimeobject-pixi-renderer.js
60 lines (48 loc) · 2.13 KB
/
dummyruntimeobject-pixi-renderer.js
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
/**
* The PIXI.js renderer for the DummyRuntimeObject.
*
* @class DummyRuntimeObjectPixiRenderer
* @constructor
* @param {gdjs.DummyRuntimeObject} runtimeObject The object to render
* @param {gdjs.RuntimeScene} runtimeScene The gdjs.RuntimeScene in which the object is
*/
gdjs.DummyRuntimeObjectPixiRenderer = function(runtimeObject, runtimeScene)
{
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 = runtimeScene.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;
runtimeScene.getLayer("").getRenderer().addRendererObject(this._text, runtimeObject.getZOrder());
this.updatePosition();
};
gdjs.DummyRuntimeObjectRenderer = gdjs.DummyRuntimeObjectPixiRenderer; //Register the class to let the engine use it.
gdjs.DummyRuntimeObjectPixiRenderer.prototype.getRendererObject = function() {
// Mandatory, return the internal PIXI object used for your object:
return this._text;
};
gdjs.DummyRuntimeObjectPixiRenderer.prototype.ensureUpToDate = function() {
this.updatePosition();
};
gdjs.DummyRuntimeObjectPixiRenderer.prototype.updatePosition = function() {
this._text.position.x = this._object.x+this._text.width/2;
this._text.position.y = this._object.y+this._text.height/2;
};
gdjs.DummyRuntimeObjectPixiRenderer.prototype.updateAngle = function() {
this._text.rotation = gdjs.toRad(this._object.angle);
};
gdjs.DummyRuntimeObjectPixiRenderer.prototype.updateOpacity = function() {
this._text.alpha = this._object.opacity / 255;
};
gdjs.DummyRuntimeObjectPixiRenderer.prototype.getWidth = function() {
return this._text.width;
};
gdjs.DummyRuntimeObjectPixiRenderer.prototype.getHeight = function() {
return this._text.height;
};