forked from 4ian/GDevelop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dummyruntimeobject.js
121 lines (104 loc) · 3.6 KB
/
dummyruntimeobject.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* A dummy object doing showing a text on screen
*
* @memberof gdjs
* @class DummyRuntimeObject
* @extends RuntimeObject
*/
gdjs.DummyRuntimeObject = function(runtimeScene, objectData) {
// *ALWAYS* call the base gdjs.RuntimeObject constructor.
gdjs.RuntimeObject.call(this, runtimeScene, objectData);
// Load any required data from the object properties.
this._property1 = objectData.content.property1;
// Create the renderer (see dummyruntimeobject-pixi-renderer.js)
if (this._renderer)
gdjs.DummyRuntimeObjectRenderer.call(this._renderer, this, runtimeScene);
else this._renderer = new gdjs.DummyRuntimeObjectRenderer(this, runtimeScene);
// *ALWAYS* call `this.onCreated()` at the very end of your object constructor.
this.onCreated();
};
gdjs.DummyRuntimeObject.prototype = Object.create(gdjs.RuntimeObject.prototype);
gdjs.DummyRuntimeObject.thisIsARuntimeObjectConstructor =
"MyDummyExtension::DummyObject"; //Replace by your extension + object name.
gdjs.DummyRuntimeObject.prototype.getRendererObject = function() {
return this._renderer.getRendererObject();
};
/**
* Called once during the game loop, before events and rendering.
* @param {gdjs.RuntimeScene} runtimeScene The gdjs.RuntimeScene the object belongs to.
*/
gdjs.DummyRuntimeObject.prototype.update = function(runtimeScene) {
// This is an example: typically you want to make sure the renderer
// is up to date with the object.
this._renderer.ensureUpToDate();
};
/**
* Initialize the extra parameters that could be set for an instance.
* @private
*/
gdjs.DummyRuntimeObject.prototype.extraInitializationFromInitialInstance = function(
initialInstanceData
) {
// For example:
// this.setSomething(initialInstanceData.something);
};
/**
* Update the object position.
* @private
*/
gdjs.DummyRuntimeObject.prototype._updatePosition = function() {
// This is an example: typically you want to tell the renderer to update
// the position of the object.
this._renderer.updatePosition();
};
/**
* Set object position on X axis.
*/
gdjs.DummyRuntimeObject.prototype.setX = function(x) {
gdjs.RuntimeObject.prototype.setX.call(this, x); // Always call the parent method first.
this._updatePosition();
};
/**
* Set object position on Y axis.
*/
gdjs.DummyRuntimeObject.prototype.setY = function(y) {
gdjs.RuntimeObject.prototype.setY.call(this, y); // Always call the parent method first.
this._updatePosition();
};
/**
* Set the angle of the object.
* @param {number} angle The new angle of the object
*/
gdjs.DummyRuntimeObject.prototype.setAngle = function(angle) {
gdjs.RuntimeObject.prototype.setAngle.call(this, angle); // Always call the parent method first.
this._renderer.updateAngle(); // Tell the renderer to update the rendered object
};
/**
* Set object opacity.
*/
gdjs.DummyRuntimeObject.prototype.setOpacity = function(opacity) {
if (opacity < 0) opacity = 0;
if (opacity > 255) opacity = 255;
this.opacity = opacity;
this._renderer.updateOpacity(); // Tell the renderer to update the rendered object
};
/**
* Get object opacity.
*/
gdjs.DummyRuntimeObject.prototype.getOpacity = function() {
return this.opacity;
};
/**
* Get the text that must be displayed by the dummy object.
*/
gdjs.DummyRuntimeObject.prototype.getText = function() {
return this._property1;
};
/**
* A dummy method that can be called from events
*/
gdjs.DummyRuntimeObject.prototype.myMethod = function(number1, text1) {
console.log("Congrats, this method was called on a DummyRuntimeObject");
console.log("Here is the object:", this);
console.log("Here are the arguments passed from events:", number1, text1);
};