@makefully/platypus 4.1.4 → 4.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +4 -2
  3. package/lib/platypus.js +1 -1
  4. package/package.json +7 -2
  5. package/src/AABB.js +685 -0
  6. package/src/ActionState.js +121 -0
  7. package/src/AssetManager.js +206 -0
  8. package/src/CollisionData.js +96 -0
  9. package/src/CollisionDataContainer.js +127 -0
  10. package/src/CollisionShape.js +315 -0
  11. package/src/Component.js +231 -0
  12. package/src/Data.js +64 -0
  13. package/src/DataMap.js +204 -0
  14. package/src/Entity.js +404 -0
  15. package/src/EntityLinker.js +113 -0
  16. package/src/EventHandler.js +115 -0
  17. package/src/EventHandlerList.js +251 -0
  18. package/src/Game.js +840 -0
  19. package/src/Gamepad.js +175 -0
  20. package/src/ID3CaptionPlayer.js +61 -0
  21. package/src/Messenger.js +365 -0
  22. package/src/PIXIAnimation.js +622 -0
  23. package/src/RandomSet.js +140 -0
  24. package/src/SFXPlayer.js +120 -0
  25. package/src/StateMap.js +252 -0
  26. package/src/Storage.js +152 -0
  27. package/src/TickerClient.js +48 -0
  28. package/src/TickerServer.js +23 -0
  29. package/src/TimeEvent.js +50 -0
  30. package/src/TimeEventList.js +100 -0
  31. package/src/VOPlayer.js +684 -0
  32. package/src/Vector.js +702 -0
  33. package/src/components/AIChaser.js +161 -0
  34. package/src/components/AIPacer.js +107 -0
  35. package/src/components/AudioMusic.js +151 -0
  36. package/src/components/AudioSFX.js +673 -0
  37. package/src/components/AudioVO.js +301 -0
  38. package/src/components/CollisionBasic.js +826 -0
  39. package/src/components/CollisionFilter.js +74 -0
  40. package/src/components/CollisionGroup.js +448 -0
  41. package/src/components/CollisionTiles.js +608 -0
  42. package/src/components/ComponentSwitcher.js +173 -0
  43. package/src/components/ControllerInput.js +65 -0
  44. package/src/components/Counter.js +165 -0
  45. package/src/components/EntityCamera.js +215 -0
  46. package/src/components/EntityContainer.js +549 -0
  47. package/src/components/EntityController.js +541 -0
  48. package/src/components/HandlerCamera.js +1052 -0
  49. package/src/components/HandlerCollision.js +1318 -0
  50. package/src/components/HandlerController.js +291 -0
  51. package/src/components/HandlerLogic.js +394 -0
  52. package/src/components/HandlerRender.js +217 -0
  53. package/src/components/Interactive.js +502 -0
  54. package/src/components/LevelBuilder.js +524 -0
  55. package/src/components/LogicAngularMovement.js +154 -0
  56. package/src/components/LogicAttachment.js +265 -0
  57. package/src/components/LogicButton.js +466 -0
  58. package/src/components/LogicCarrier.js +39 -0
  59. package/src/components/LogicDestroyMe.js +58 -0
  60. package/src/components/LogicDirectionalMovement.js +325 -0
  61. package/src/components/LogicDragDrop.js +371 -0
  62. package/src/components/LogicImpactLaunch.js +144 -0
  63. package/src/components/LogicPacingPlatform.js +64 -0
  64. package/src/components/LogicPortable.js +112 -0
  65. package/src/components/LogicPortal.js +115 -0
  66. package/src/components/LogicPushable.js +98 -0
  67. package/src/components/LogicRebounder.js +136 -0
  68. package/src/components/LogicRegionSpawner.js +139 -0
  69. package/src/components/LogicRotationalMovement.js +205 -0
  70. package/src/components/LogicSpawner.js +159 -0
  71. package/src/components/LogicStateMachine.js +382 -0
  72. package/src/components/LogicSwitch.js +77 -0
  73. package/src/components/LogicTeleportee.js +68 -0
  74. package/src/components/LogicTeleporter.js +93 -0
  75. package/src/components/LogicTimer.js +178 -0
  76. package/src/components/LogicWindUpRacer.js +179 -0
  77. package/src/components/Motion.js +371 -0
  78. package/src/components/Mover.js +566 -0
  79. package/src/components/Node.js +289 -0
  80. package/src/components/NodeMap.js +295 -0
  81. package/src/components/NodeResident.js +636 -0
  82. package/src/components/Orientation.js +697 -0
  83. package/src/components/RandomEvents.js +73 -0
  84. package/src/components/RelativePosition.js +204 -0
  85. package/src/components/RelayFamily.js +106 -0
  86. package/src/components/RelayGame.js +53 -0
  87. package/src/components/RelayLinker.js +94 -0
  88. package/src/components/RelayParent.js +57 -0
  89. package/src/components/RelaySelf.js +55 -0
  90. package/src/components/Render.js +178 -0
  91. package/src/components/RenderAnimator.js +275 -0
  92. package/src/components/RenderContainer.js +646 -0
  93. package/src/components/RenderDebug.js +319 -0
  94. package/src/components/RenderDestroyMe.js +59 -0
  95. package/src/components/RenderLottie.js +149 -0
  96. package/src/components/RenderProgress.js +120 -0
  97. package/src/components/RenderSpine.js +833 -0
  98. package/src/components/RenderSprite.js +527 -0
  99. package/src/components/RenderText.js +147 -0
  100. package/src/components/RenderTiles.js +1391 -0
  101. package/src/components/SceneChanger.js +128 -0
  102. package/src/components/TiledLoader.js +1451 -0
  103. package/src/components/Timeline.js +314 -0
  104. package/src/components/Tutorial.js +267 -0
  105. package/src/components/Tween.js +296 -0
  106. package/src/components/VoiceOver.js +373 -0
  107. package/src/components/XHR.js +129 -0
  108. package/src/components/index.js +79 -0
  109. package/src/factory.js +305 -0
  110. package/src/index.js +159 -0
  111. package/src/mixins/PIXI.Graphics.js +41 -0
  112. package/src/platypus.css +68 -0
  113. package/src/sayHello.js +50 -0
  114. package/src/shapes/Capsule.js +74 -0
  115. package/src/shapes/Circle.js +43 -0
  116. package/src/shapes/Ellipse.js +117 -0
  117. package/src/shapes/Point.js +191 -0
  118. package/src/shapes/Polygon.js +112 -0
  119. package/src/shapes/Polyline.js +97 -0
  120. package/src/shapes/Rectangle.js +78 -0
  121. package/src/shapes/RoundedRectangle.js +33 -0
  122. package/src/shapes/Segment.js +346 -0
  123. package/src/shapes/adjustedXY.js +19 -0
  124. package/src/shapes/castFromBox2D.js +92 -0
  125. package/src/shapes/castFromObject.js +53 -0
  126. package/src/shapes/castFromPixiGraphics.js +6 -0
  127. package/src/shapes/castFromPixiShape.js +89 -0
  128. package/src/shapes/castToBox2D.js +190 -0
  129. package/src/shapes/castToPixiGraphics.js +100 -0
  130. package/src/shapes/castToPixiShape.js +61 -0
  131. package/src/shapes/checkPointsMap.js +313 -0
  132. package/src/shapes/index.js +35 -0
  133. package/src/utils/array.js +73 -0
  134. package/src/utils/string.js +39 -0
@@ -0,0 +1,466 @@
1
+ import AABB from '../AABB.js';
2
+ import Data from '../Data.js';
3
+ import StateMap from '../StateMap.js';
4
+ import createComponentClass from '../factory.js';
5
+
6
+ export default (function () {
7
+ return createComponentClass(/** @lends platypus.components.LogicButton.prototype */{
8
+
9
+ id: 'LogicButton',
10
+
11
+ properties: {
12
+ /**
13
+ * The event to trigger when pressed.
14
+ *
15
+ * @property onPress
16
+ * @type String
17
+ * @default ""
18
+ */
19
+ "onPress": "",
20
+
21
+ /**
22
+ * The event to trigger when released.
23
+ *
24
+ * @property onRelease
25
+ * @type String
26
+ * @default ""
27
+ */
28
+ "onRelease": "",
29
+
30
+ /**
31
+ * The event to trigger when cancelled.
32
+ *
33
+ * @property onCancel
34
+ * @type String
35
+ * @default ""
36
+ */
37
+ "onCancel": "",
38
+
39
+ /**
40
+ * The event to trigger when the user mouses over the button
41
+ *
42
+ * @property hoverAudio
43
+ * @type String|String[]|Message[]
44
+ * @default ""
45
+ */
46
+ "onHover": "",
47
+
48
+ /**
49
+ * Whether this button's actions should be limited to the initial press/release.
50
+ *
51
+ * @property useOnce
52
+ * @type Boolean
53
+ * @default false
54
+ */
55
+ "useOnce": false,
56
+
57
+ /**
58
+ * Whether this button should start disabled.
59
+ *
60
+ * @property disabled
61
+ * @type Boolean
62
+ * @default false
63
+ */
64
+ "disabled": false,
65
+
66
+ /**
67
+ * Determines whether this button should behave as a toggle.
68
+ *
69
+ * @property toggle
70
+ * @type Boolean
71
+ * @default false
72
+ */
73
+ "toggle": false,
74
+
75
+ /**
76
+ * Specifies whether the button starts off 'pressed'; typically only useful for toggle buttons.
77
+ *
78
+ * @property pressed
79
+ * @type Boolean
80
+ * @default false
81
+ */
82
+ "pressed": false,
83
+
84
+ /**
85
+ * State that entity match be in for LogicButton to be enabled.
86
+ *
87
+ * @property validState
88
+ * @type String|StateMap
89
+ * @default '!disabled'
90
+ */
91
+ validState: '!disabled',
92
+
93
+ /**
94
+ * State that parent entity match be in for LogicButton to be enabled. Default is "" unless "baton" is true in which case the default is "!baton"
95
+ *
96
+ * @property validParentState
97
+ * @type String|StateMap
98
+ * @default ''
99
+ */
100
+ validParentState: '',
101
+
102
+ /**
103
+ * Whether multitouch is disallowed for this button to work: ie no other "baton: true" button may be currently pressed in order for this button to be enabled. This is useful for instances where a button may cause a conflict if another button is also activated.
104
+ *
105
+ * @property baton
106
+ * @type Boolean
107
+ * @default false
108
+ */
109
+ baton: false
110
+ },
111
+
112
+ publicProperties: {
113
+ /**
114
+ * This sets the distance in world units from the bottom of the camera's world viewport. If set, it will override the entity's y coordinate. This property is accessible on the entity as `entity.bottom`.
115
+ *
116
+ * @property bottom
117
+ * @type Number
118
+ * @default null
119
+ */
120
+ "bottom": null,
121
+
122
+ /**
123
+ * This sets the distance in world units from the left of the camera's world viewport. If set, it will override the entity's x coordinate. This property is accessible on the entity as `entity.left`.
124
+ *
125
+ * @property left
126
+ * @type Number
127
+ * @default null
128
+ */
129
+ "left": null,
130
+
131
+ /**
132
+ * This sets the distance in world units from the right of the camera's world viewport. If set, it will override the entity's x coordinate. This property is accessible on the entity as `entity.right`.
133
+ *
134
+ * @property right
135
+ * @type Number
136
+ * @default null
137
+ */
138
+ "right": null,
139
+
140
+ /**
141
+ * This sets the distance in world units from the top of the camera's world viewport. If set, it will override the entity's y coordinate. This property is accessible on the entity as `entity.top`.
142
+ *
143
+ * @property top
144
+ * @type Number
145
+ * @default null
146
+ */
147
+ "top": null
148
+ },
149
+
150
+ /**
151
+ * Provides button functionality for a RenderSprite component.
152
+ *
153
+ * @memberof platypus.components
154
+ * @uses platypus.Component
155
+ * @constructs
156
+ * @listens platypus.Entity#camera-update
157
+ * @listens platypus.Entity#disable
158
+ * @listens platypus.Entity#enable
159
+ * @listens platypus.Entity#handle-logic
160
+ * @listens platypus.Entity#highlight
161
+ * @listens platypus.Entity#pointerdown
162
+ * @listens platypus.Entity#pointerout
163
+ * @listens platypus.Entity#pointerover
164
+ * @listens platypus.Entity#pressup
165
+ * @listens platypus.Entity#toggle-disabled
166
+ * @listens platypus.Entity#toggle-highlight
167
+ * @listens platypus.Entity#unhighlight
168
+ * @fires platypus.Entity#pressed
169
+ * @fires platypus.Entity#cancelled
170
+ * @fires platypus.Entity#released
171
+ */
172
+ initialize: function () {
173
+ const
174
+ {state} = this.owner;
175
+
176
+ this.aabb = AABB.setUp();
177
+ this.lastBottom = null;
178
+ this.lastLeft = null;
179
+ this.lastRight = null;
180
+ this.lastTop = null;
181
+
182
+ this.state = state;
183
+ state.set('disabled', this.disabled);
184
+ state.set('released', !this.pressed);
185
+ state.set('pressed', this.pressed);
186
+ state.set('highlighted', false);
187
+ this.validParentState = StateMap.setUp(this.validParentState);
188
+ this.validState = StateMap.setUp(this.validState);
189
+ if (this.baton) {
190
+ this.validParentState.set('baton', false);
191
+ this.owner.parent.state.set('baton', false);
192
+ this.batonIsMine = false;
193
+ }
194
+ this.owner.container.cursor = this.disabled ? null : 'pointer';
195
+ this.cancelled = false;
196
+ this.readyToToggle = false;
197
+ },
198
+
199
+ events: {
200
+ "handle-logic": function () {
201
+ const
202
+ {bottom, left, right, top} = this;
203
+
204
+ if ((this.lastBottom !== bottom) || (this.lastLeft !== left) || (this.lastRight !== right) || (this.lastTop !== top)) {
205
+ this.updatePosition(this.aabb);
206
+ this.lastBottom = bottom;
207
+ this.lastLeft = left;
208
+ this.lastRight = right;
209
+ this.lastTop = top;
210
+ }
211
+ },
212
+
213
+ "camera-update": function (camera) {
214
+ this.aabb.set(camera.viewport);
215
+ this.updatePosition(this.aabb);
216
+ },
217
+
218
+ "pointerdown": function (eventData) {
219
+ if (this.checkStateValidity()) {
220
+ if (this.toggle) {
221
+ this.readyToToggle = true;
222
+ } else {
223
+ if (this.baton) {
224
+ this.batonIsMine = true;
225
+ this.owner.parent.state.set('baton', true);
226
+ }
227
+
228
+ if (this.onPress) {
229
+ this.owner.trigger(this.onPress);
230
+ }
231
+
232
+ /**
233
+ * This event is triggered when the button is pressed to mimic keypress events. If the button is a toggle button, this only occurs on up-to-down.
234
+ *
235
+ * @event platypus.Entity#pressed
236
+ * @param buttonState {platypus.Data} The state of the button
237
+ * @param buttonState.pressed {Boolean} This is `true` for the 'pressed' event.
238
+ * @param buttonState.released {Boolean} This is `false` for the 'pressed' event.
239
+ * @param buttonState.triggered {Boolean} This is `true` for the 'pressed' event.
240
+ * @param buttonState.entity {platypus.Entity} The entity for which the original event occurred.
241
+ */
242
+ this.updateStateAndTrigger('pressed');
243
+ if (eventData && eventData.pixiEvent && eventData.pixiEvent.stopPropagation) { // ensure a properly formed event has been sent
244
+ eventData.pixiEvent.stopPropagation();
245
+ }
246
+ }
247
+ }
248
+ },
249
+
250
+ "pressup": function (eventData) {
251
+ const
252
+ {state} = this;
253
+
254
+ if (this.baton && this.batonIsMine) {
255
+ this.batonIsMine = false;
256
+ this.owner.parent.state.set('baton', false);
257
+ }
258
+
259
+ if (this.checkStateValidity()) {
260
+ if (this.cancelled) {
261
+ if (this.onCancel) {
262
+ this.owner.trigger(this.onCancel);
263
+ }
264
+
265
+ /**
266
+ * This event is triggered when the button is pressed and the mouse/touch is dragged off-target before release.
267
+ *
268
+ * @event platypus.Entity#cancelled
269
+ * @param buttonState {platypus.Data} The state of the button
270
+ * @param buttonState.pressed {Boolean} This is `false` for the 'cancelled' event.
271
+ * @param buttonState.released {Boolean} This is `true` for the 'cancelled' event.
272
+ * @param buttonState.triggered {Boolean} This is `false` for the 'cancelled' event.
273
+ * @param buttonState.entity {platypus.Entity} The entity for which the original event occurred.
274
+ */
275
+ this.updateStateAndTrigger('cancelled');
276
+ } else if (this.toggle) {
277
+ if (this.readyToToggle) {
278
+ if (state.get('pressed')) {
279
+ this.updateStateAndTrigger('released');
280
+ } else {
281
+ this.updateStateAndTrigger('pressed');
282
+ }
283
+ }
284
+ } else {
285
+ if (this.onRelease) {
286
+ this.owner.trigger(this.onRelease);
287
+ }
288
+
289
+ /**
290
+ * This event is triggered when the button is released, or on the down-to-up change for toggle buttons.
291
+ *
292
+ * @event platypus.Entity#released
293
+ * @param buttonState {platypus.Data} The state of the button
294
+ * @param buttonState.pressed {Boolean} This is `false` for the 'released' event.
295
+ * @param buttonState.released {Boolean} This is `true` for the 'released' event.
296
+ * @param buttonState.triggered {Boolean} This is `false` for the 'released' event.
297
+ * @param buttonState.entity {platypus.Entity} The entity for which the original event occurred.
298
+ */
299
+ this.updateStateAndTrigger('released');
300
+ }
301
+ if (eventData && eventData.pixiEvent && eventData.pixiEvent.stopPropagation) { // ensure a properly formed event has been sent
302
+ eventData.pixiEvent.stopPropagation();
303
+ }
304
+
305
+ // Doing this prevents the call from reccurring.
306
+ if (!this.cancelled && this.useOnce && this.removeEventListener) { //Second check is to ensure method exists which won't be the case if a result of the press is the button being destroyed.
307
+ this.removeEventListener('pointerdown');
308
+ this.removeEventListener('pressup');
309
+ this.state.set('disabled', true);
310
+ this.owner.container.cursor = null;
311
+ }
312
+ }
313
+
314
+ this.cancelled = false;
315
+ this.readyToToggle = false;
316
+ },
317
+
318
+ "pointerover": function () {
319
+ if (this.onHover) {
320
+ this.owner.trigger(this.onHover);
321
+ }
322
+ if (this.state.get('pressed')) {
323
+ this.cancelled = false;
324
+ }
325
+ },
326
+
327
+ "pointerout": function () {
328
+ if (this.state.get('pressed')) {
329
+ this.cancelled = true;
330
+ }
331
+ },
332
+
333
+ /**
334
+ * Disables the entity.
335
+ *
336
+ * @event platypus.Entity#disable
337
+ */
338
+ "disable": function () {
339
+ this.state.set('disabled', true);
340
+ this.owner.container.cursor = null;
341
+ },
342
+
343
+ /**
344
+ * Enables the entity.
345
+ *
346
+ * @event platypus.Entity#enable
347
+ */
348
+ "enable": function () {
349
+ this.state.set('disabled', false);
350
+ this.owner.container.cursor = 'pointer';
351
+ },
352
+
353
+ /**
354
+ * Toggles whether the entity is disabled.
355
+ *
356
+ * @event platypus.Entity#toggle-disabled
357
+ */
358
+ "toggle-disabled": function () {
359
+ const
360
+ value = this.state.get('disabled');
361
+
362
+ this.owner.container.cursor = value ? 'pointer': null;
363
+ this.state.set('disabled', !value);
364
+ },
365
+
366
+ /**
367
+ * Sets the entity's highlighted state to `true`.
368
+ *
369
+ * @event platypus.Entity#highlight
370
+ */
371
+ "highlight": function () {
372
+ this.state.set('highlighted', true);
373
+ },
374
+
375
+ /**
376
+ * Sets the entity's highlighted state to `false`.
377
+ *
378
+ * @event platypus.Entity#unhighlight
379
+ */
380
+ "unhighlight": function () {
381
+ this.state.set('highlighted', false);
382
+ },
383
+
384
+ /**
385
+ * Toggles the entity's highlighted state.
386
+ *
387
+ * @event platypus.Entity#toggle-highlight
388
+ */
389
+ "toggle-highlight": function () {
390
+ const
391
+ {state} = this;
392
+
393
+ state.set('highlighted', !state.get('highlighted'));
394
+ }
395
+ },
396
+
397
+ methods: {
398
+ checkStateValidity () {
399
+ const
400
+ {owner, validParentState, validState} = this;
401
+
402
+ return owner.state.includes(validState) && owner.parent.state.includes(validParentState);
403
+ },
404
+
405
+ updatePosition (vp) {
406
+ const
407
+ {bottom, left, owner, right, top} = this;
408
+
409
+ if (typeof left === 'number') {
410
+ owner.x = vp.left + left;
411
+ } else if (typeof right === 'number') {
412
+ owner.x = vp.right - right;
413
+ }
414
+
415
+ if (typeof top === 'number') {
416
+ owner.y = vp.top + top;
417
+ } else if (typeof bottom === 'number') {
418
+ owner.y = vp.bottom - bottom;
419
+ }
420
+ },
421
+
422
+ updateStateAndTrigger (event) {
423
+ const
424
+ {owner, state} = this,
425
+ pressed = state.get('pressed'),
426
+ released = state.get('released');
427
+ let toggled = false;
428
+
429
+ if (released && (event === 'pressed')) {
430
+ state.set('pressed', true);
431
+ state.set('released', false);
432
+ toggled = true;
433
+ } else if (pressed && ((event === 'released') || (event === 'cancelled'))) {
434
+ state.set('pressed', false);
435
+ state.set('released', true);
436
+ toggled = true;
437
+ }
438
+
439
+ if (toggled) {
440
+ const
441
+ message = Data.setUp(
442
+ 'released', pressed,
443
+ 'pressed', released,
444
+ 'triggered', released,
445
+ 'entity', owner
446
+ );
447
+
448
+ owner.triggerEvent(event, message);
449
+ message.recycle();
450
+ }
451
+ },
452
+
453
+ destroy: function () {
454
+ if (this.baton && this.batonIsMine) {
455
+ this.batonIsMine = false;
456
+ this.owner.parent.state.set('baton', false);
457
+ }
458
+
459
+ this.aabb.recycle();
460
+ this.aabb = null;
461
+ this.owner.container.cursor = null;
462
+ this.state = null;
463
+ }
464
+ }
465
+ });
466
+ }());
@@ -0,0 +1,39 @@
1
+ /* global platypus */
2
+ import createComponentClass from '../factory.js';
3
+
4
+ export default createComponentClass(/** @lends platypus.components.LogicCarrier.prototype */{
5
+
6
+ id: 'LogicCarrier',
7
+
8
+ /**
9
+ * This component allows this entity carry other entities with which it collides. Entities that this component should carry need to have a [[Logic-Portable]] component attached to notify this entity that they are portable.
10
+ *
11
+ * @memberof platypus.components
12
+ * @uses platypus.Component
13
+ * @constructs
14
+ * @listens platypus.Entity#load
15
+ * @listens platypus.Entity#carry-me
16
+ * @listens platypus.Entity#release-me
17
+ * @fires platypus.Entity#add-collision-entity
18
+ * @fires platypus.Entity#remove-collision-entity
19
+ */
20
+ initialize: function () {},
21
+
22
+ events: {
23
+ "load": function () {
24
+ if (!this.owner.triggerEvent('add-collision-entity', this.owner)) {
25
+ // This message wasn't handled, so add a CollisionGroup component and try again!
26
+ this.owner.addComponent(new platypus.components.CollisionGroup(this.owner, {}));
27
+ this.owner.triggerEvent('add-collision-entity', this.owner);
28
+ }
29
+ },
30
+
31
+ "carry-me": function (resp) {
32
+ this.owner.triggerEvent('add-collision-entity', resp.entity);
33
+ },
34
+
35
+ "release-me": function (resp) {
36
+ this.owner.triggerEvent('remove-collision-entity', resp.entity);
37
+ }
38
+ }
39
+ });
@@ -0,0 +1,58 @@
1
+ import createComponentClass from '../factory.js';
2
+
3
+ export default (function () {
4
+ return createComponentClass(/** @lends platypus.components.LogicDestroyMe.prototype */{
5
+ id: 'LogicDestroyMe',
6
+
7
+ properties: {
8
+ /**
9
+ * Time in milliseconds after the "destroy-me" message is heard before entity should be removed.
10
+ *
11
+ * @property delay
12
+ * @type number
13
+ * @default 0
14
+ */
15
+ delay: 0,
16
+
17
+ /**
18
+ * Whether this entity has been destroyed. Typically `false` until a "destroy-me" event has been triggered.
19
+ *
20
+ * @property destroyed
21
+ * @type boolean
22
+ * @default false
23
+ */
24
+ destroyed: false
25
+ },
26
+
27
+ /**
28
+ * This component allows an entity to be removed from the stage when "destroy-me" is triggered.
29
+ *
30
+ * @memberof platypus.components
31
+ * @uses platypus.Component
32
+ * @constructs
33
+ * @listens platypus.Entity#destroy-me
34
+ * @listens platypus.Entity#prepare-logic
35
+ */
36
+ initialize: function () {},
37
+
38
+ events: {
39
+ "prepare-logic": function ({delta}) {
40
+ if (this.destroyed && !this.owner.state.get('paused')) {
41
+ this.delay -= delta;
42
+ if (this.delay <= 0) {
43
+ this.owner.parent.removeEntity(this.owner);
44
+ }
45
+ }
46
+ },
47
+
48
+ /**
49
+ * This component will set the entity up for removal on receiving this message.
50
+ *
51
+ * @event platypus.Entity#destroy-me
52
+ */
53
+ "destroy-me": function () {
54
+ this.destroyed = true;
55
+ }
56
+ }
57
+ });
58
+ }());