-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_DisplayGroup.js.html
902 lines (800 loc) · 35.7 KB
/
display_DisplayGroup.js.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: display/DisplayGroup.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: display/DisplayGroup.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>//------------------------------------------------------------------------------
// Constructor scope
//------------------------------------------------------------------------------
/**
* Creates a new instance of the DisplayGroup class.
*
* @constructor
*
* @param {rune.display.DisplayObjectContainer} container Display object container object that will contain members.
*
* @class
* @classdesc
*
* The DisplayGroup class represents a collection (usually a subset) of display
* objects from one and the same display object container. The group offers
* easy access to the collection as you do not have to go through the entire
* display object container to find them. The contents of the group are
* automatically synchronized with the contents of the display object
* container, ie if an object is added to the group, it is also added as a
* child object to the container. A group also offers fast and easy collision
* handling of display objects that are part of the group, but the group is not
* limited to handling internal collisions; it is also possible to hit test
* against objects that are not group members.
*/
rune.display.DisplayGroup = function(container) {
//--------------------------------------------------------------------------
// Public properties
//--------------------------------------------------------------------------
/**
* Whether the group is active (true) or not (false). Inactive groups are
* not automatically updated by the group manager.
*
* @type {boolean}
* @default true
*/
this.active = true;
//--------------------------------------------------------------------------
// Protected properties
//--------------------------------------------------------------------------
/**
* Internal cache for the member's calculated area. This is calculated for
* each update when the object is active. If the object is inactive, the
* area is calculated on request, ie when the getArea() method is called.
*
* @type {rune.geom.Rectangle}
* @protected
* @ignore
*/
this.m_area = new rune.geom.Rectangle();
/**
* The display object container that contains all group members.
*
* @type {rune.display.DisplayObjectContainer}
* @protected
* @ignore
*/
this.m_container = container;
/**
* Register of group members. If an object is a member, it must be present
* as a child to the display object container.
*
* @type {Array.<rune.display.DisplayObject>}
* @protected
* @ignore
*/
this.m_members = [];
/**
* Internal quad tree.
*
* @type {rune.display.Quadtree}
* @protected
* @ignore
*/
this.m_quadtree = null;
};
//------------------------------------------------------------------------------
// Public prototype getter and setter methods
//------------------------------------------------------------------------------
/**
* Reference to the application's entry point class, ie. the main class of the
* application. Useful for accessing the application's subsystem.
*
* @member {rune.system.Main} application
* @memberof rune.display.DisplayGroup
* @instance
* @readonly
*/
Object.defineProperty(rune.display.DisplayGroup.prototype, "application", {
/**
* @this rune.display.DisplayGroup
* @ignore
*/
get : function() {
return rune.system.Application['instance'];
}
});
/**
* Reference to the current scene's camera system.
*
* @member {rune.camera.Cameras} cameras
* @memberof rune.display.DisplayGroup
* @instance
* @readonly
*/
Object.defineProperty(rune.display.DisplayGroup.prototype, "cameras", {
/**
* @this rune.display.DisplayGroup
* @ignore
*/
get : function() {
return this['application']['scenes']['selected']['cameras'];
}
});
/**
* Reference to the display object container to which the group is linked. When
* new members are added to the group, they are also added to the display
* object container's display list.
*
* @member {rune.display.DisplayObject} container
* @memberof rune.display.DisplayGroup
* @instance
* @readonly
*/
Object.defineProperty(rune.display.DisplayGroup.prototype, "container", {
/**
* @this rune.display.DisplayGroup
* @ignore
*/
get : function() {
return this.m_container;
}
});
/**
* Reference to the application's subsystem for connected gamepad devices.
*
* @member {rune.input.Gamepads} gamepads
* @memberof rune.display.DisplayGroup
* @instance
* @readonly
*/
Object.defineProperty(rune.display.DisplayGroup.prototype, "gamepads", {
/**
* @this rune.display.DisplayGroup
* @ignore
*/
get : function() {
return rune.system.Application['instance']['inputs']['gamepads'];
}
});
/**
* Reference to the subsystem representing the keyboard input.
*
* @member {rune.input.Keyboard} keyboard
* @memberof rune.display.DisplayGroup
* @instance
* @readonly
*/
Object.defineProperty(rune.display.DisplayGroup.prototype, "keyboard", {
/**
* @this rune.display.DisplayGroup
* @ignore
*/
get : function() {
return rune.system.Application['instance']['inputs']['keyboard'];
}
});
/**
* The number of members included in the group. Note that this number is not
* necessarily the same as the number of children in the display object
* container to which the group is linked.
*
* @member {number} numMembers
* @memberof rune.display.DisplayGroup
* @instance
* @readonly
*/
Object.defineProperty(rune.display.DisplayGroup.prototype, "numMembers", {
/**
* @this rune.display.DisplayGroup
* @ignore
*/
get : function() {
return this.m_members.length;
}
});
/**
* Whether the group should use a quad tree to improve hit testing performance.
* Note that the quad tree can not guarantee noticeably better performance, but
* it should be evaluated when you experience performance problems with the
* quad tree disabled.
*
* @member {boolean} useQuadtree
* @memberof rune.display.DisplayGroup
* @instance
*/
Object.defineProperty(rune.display.DisplayGroup.prototype, "useQuadtree", {
/**
* @this rune.display.DisplayGroup
* @ignore
*/
get : function() {
return (this.m_quadtree != null);
},
/**
* @this rune.display.DisplayGroup
* @ignore
*/
set : function(value) {
if (this.m_quadtree == null && value == true) {
this.m_constructQuadtree();
} else {
this.m_disposeQuadtree();
}
},
});
//------------------------------------------------------------------------------
// Public prototype methods (API)
//------------------------------------------------------------------------------
/**
* Adds a member to the display group. Note that attempts to add existing
* members are denied. The method always returns a boolean that indicates
* whether the extension was successful (true) or not (false). When an item is
* added to a group, it is automatically removed from any other groups, and it
* is also removed from other display lists. This means that an object can only
* be a member of one group at a time and that it is always available in the
* group's container object view list as long as it is a member of that group.
*
* @param {rune.display.DisplayObject} member Prospect to add.
*
* @returns {boolean}
*/
rune.display.DisplayGroup.prototype.addMember = function(member) {
var index = this.m_members.indexOf(member);
if (index === -1) {
if (this.m_container.hasChild(member) == false) {
this.m_container.addChild(member);
}
this.m_members.push(member);
member.setGroup(this);
return true;
}
return false;
};
/**
* Executes a callback method for each member of the group. Reference to the
* current member and its member index are sent to the callback method as
* arguments.
*
* @param {Function} callback Call function.
* @param {Object} scope Scope of execution.
*
* @returns {undefined}
*/
rune.display.DisplayGroup.prototype.forEachMember = function(callback, scope) {
for (var i = 0; i < this.m_members.length; i++) {
callback.call(scope, this.m_members[i], i);
}
};
/**
* Calculates the geometric area that the members of the group allocate.
* The method returns a rectangle object that encloses all members of the group.
*
* @param {rune.geom.Rectangle} [rect] Rectangle to overwrite, if nothing is specified, a new rectangle object is returned.
*
* @returns {rune.geom.Rectangle}
* @private
*/
rune.display.DisplayGroup.prototype.getArea = function(rect) {
if (this.active == true) {
if (rect != null) {
return rune.geom.Rectangle.copy(this.m_area, rect);
} else {
return this.m_area;
}
} else {
return this.m_calculateArea(rect);
}
};
/**
* Retrieves a member object at a specific index. Note that the member index is
* not necessarily the same as the object's child index in the display object
* container.
*
* @param {number} index The index position of the member object.
*
* @throws {RangeError} Throws if the index does not exist in the member list.
*
* @returns {rune.display.DisplayObject} The member object at the specified index position.
*/
rune.display.DisplayGroup.prototype.getMemberAt = function(index) {
if (index > -1 && index < this.m_members.length) {
return this.m_members[index];
} else throw new RangeError();
};
/**
* Retrieves the list of all members. This method is primarily intended for
* internal use. Consider it read-only, as changes in the structure can cause
* problems for the group.
*
* @returns {Array.<rune.display.DisplayObject>}
*/
rune.display.DisplayGroup.prototype.getMembers = function() {
return this.m_members;
};
/**
* If the useQuadtree property is set to true, only member objects that are in
* close proximity to the argument object are returned; otherwise a list of all
* members is returned.
*
* @param {rune.display.DisplayObject} obj Main object.
*
* @return {Array.<rune.display.DisplayObject>}
*/
rune.display.DisplayGroup.prototype.getMembersCloseTo = function(obj) {
if (this.m_quadtree != null) {
var prospects = this.m_quadtree.retrieve(obj);
var i = prospects.indexOf(obj);
if (i > -1) {
prospects.splice(i, 1);
}
return prospects;
}
return this.m_members;
};
/**
* Returns whether an object is a member of the group (true) or not (false.)
*
* @param {rune.display.DisplayObject} prospect Main object.
*
* @returns {boolean}
*/
rune.display.DisplayGroup.prototype.hasMember = function(prospect) {
return (this.m_members.indexOf(prospect) > -1) ? true : false;
};
/**
* Performs hit detection between an object and all members of the group. For
* each hit, a callback method is also executed, which attaches the two objects
* that collide as arguments to the method.
*
* @param {rune.display.DisplayObject|rune.display.DisplayGroup|rune.geom.Point|Array} obj Object to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean} Returns true if any hit was found, otherwise false.
*/
rune.display.DisplayGroup.prototype.hitTest = function(obj, callback, scope) {
if (obj instanceof rune.display.DisplayGroup) return this.hitTestGroup(obj, callback, scope);
else if (obj instanceof rune.display.DisplayObject) return this.hitTestObject(obj, callback, scope);
else if (obj instanceof rune.geom.Point) return this.hitTestPoint(obj, callback, scope);
else if (obj instanceof Array) return this.hitTestContentOf(obj, callback, scope);
else return false;
};
/**
* Performs hit detection between an object and all members of the group. If a
* hit is detected, the objects are separated according to their physical
* properties. For each hit, a callback method is also executed, which attaches
* the two objects that collide as arguments to the method.
*
* @param {rune.display.DisplayObject|rune.display.DisplayGroup|Array} obj Object to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean} Returns true if any hit was found, otherwise false.
*/
rune.display.DisplayGroup.prototype.hitTestAndSeparate = function(obj, callback, scope) {
if (obj instanceof rune.display.DisplayGroup) return this.hitTestAndSeparateGroup(obj, callback, scope);
else if (obj instanceof rune.display.DisplayObject) return this.hitTestAndSeparateObject(obj, callback, scope);
else if (obj instanceof Array) return this.hitTestAndSeparateContentOf(obj, callback, scope);
else return false;
};
/**
* Evaluates and handles collisions between group member hitboxes and the
* hitboxes of objects in an array.
*
* @param {Array} array The array to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean}
*/
rune.display.DisplayGroup.prototype.hitTestAndSeparateContentOf = function(array, callback, scope) {
var collide = false;
this.forEachMember(function(member) {
for (var i = 0; i < array.length; i++) {
if (member.hitTestAndSeparate(array[i], callback, scope)) {
collide = true;
}
}
}, this);
return collide;
};
/**
* Performs hit detection between members of this and another group. If a hit
* is detected, the objects are separated based on their physical properties.
* For each hit, a callback method is also executed, which attaches the two
* objects that collide as arguments to the method.
*
* @param {rune.display.DisplayGroup} group Group to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean} True if there was a collision, otherwise false.
*/
rune.display.DisplayGroup.prototype.hitTestAndSeparateGroup = function(group, callback, scope) {
var a = this.getMembers();
var b = null;
var c = false;
for (var x = 0; x < a.length; x++) {
b = group.getMembersCloseTo(a[x]);
for (var y = 0; y < b.length; y++) {
if (a[x] != b[y]) {
if (a[x].hitTestAndSeparateObject(b[y], callback, scope)) {
c = true;
}
}
}
}
return c;
};
/**
* Performs hit detection between members of this group and another display
* object. If a hit is detected, the objects are separated based on their
* physical properties. For each hit, a callback method is also executed, which
* attaches the two objects that collide as arguments to the method.
*
* @param {rune.display.DisplayObject} obj Object to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean}
*/
rune.display.DisplayGroup.prototype.hitTestAndSeparateObject = function(obj, callback, scope) {
var members = this.getMembersCloseTo(obj);
var collide = false;
for (var i = 0; i < members.length; i++) {
if (members[i].hitTestAndSeparateObject(obj, callback, scope)) {
collide = true;
}
}
return collide;
};
/**
* Evaluates collision between the hitboxes of group members and the hitboxes
* of objects in an array.
*
* @param {Array} array The array to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean}
*/
rune.display.DisplayGroup.prototype.hitTestContentOf = function(array, callback, scope) {
var collide = false;
this.forEachMember(function(member) {
for (var i = 0; i < array.length; i++) {
if (member.hitTest(array[i], callback, scope)) {
collide = true;
}
}
}, this);
return collide;
};
/**
* Hit detect all members of the group against the members of (the same or)
* another group.
*
* @param {rune.display.DisplayGroup} group The group to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean}
*/
rune.display.DisplayGroup.prototype.hitTestGroup = function(group, callback, scope) {
var a = this.getMembers();
var b = null;
var c = false;
for (var x = 0; x < a.length; x++) {
b = group.getMembersCloseTo(a[x]);
for (var y = 0; y < b.length; y++) {
if (a[x] != b[y]) {
if (a[x].hitTestObject(b[y], callback, scope)) {
c = true;
}
}
}
}
return c;
};
/**
* Hit detect all members of the group against another display object.
*
* @param {rune.display.DisplayObject} obj The display object to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean}
*/
rune.display.DisplayGroup.prototype.hitTestObject = function(obj, callback, scope) {
var members = this.getMembersCloseTo(obj);
var collide = false;
for (var i = 0; i < members.length; i++) {
if (members[i].hitTestObject(obj, callback, scope)) {
collide = true;
}
}
return collide;
};
/**
* Hit Detect all members of the group against a point. The method returns true
* if the point overlaps one of the group members, otherwise false is returned.
*
* @param {rune.geom.Point} point Point to test against.
* @param {Function} [callback] Method that is called when a collision is detected.
* @param {Object} [scope] Scope of execution of the callback method.
*
* @returns {boolean}
*/
rune.display.DisplayGroup.prototype.hitTestPoint = function(point, callback, scope) {
var collide = false;
var area = this.getArea();
if (area && area.containsPoint(point)) {
var members = this.getMembers();
for (var i = 0; i < members.length; i++) {
if (members[i].hitTestPoint(point, callback, scope)) {
collide = true;
}
}
}
return collide;
};
/**
* Removes a member from the group. Note that the member will also be removed
* from the display object's display list. It is not possible to be a member
* of the group without being available in the container object's display list.
*
* @param {rune.display.DisplayObject} member Member to be removed.
* @param {boolean} dispose Whether the member should be destroyed when it is removed.
*
* @returns {rune.display.DisplayObject}
*/
rune.display.DisplayGroup.prototype.removeMember = function(member, dispose) {
var index = this.m_members.indexOf(member);
if (index > -1) {
this.m_members.splice(index, 1);
if (member['parent'] == this.m_container) {
this.m_container.removeChild(member, false);
}
if (dispose == true) {
member.dispose();
member = null;
}
}
return (dispose) ? null : member;
};
/**
* Removes all members from the group.
*
* @param {boolean} dispose Whether the members should be destroyed when they are removed.
*
* @returns {undefined}
*/
rune.display.DisplayGroup.prototype.removeMembers = function(dispose) {
while (this.m_members.length > 0) {
this.removeMember(this.getMemberAt(0), dispose);
}
};
//------------------------------------------------------------------------------
// Public prototype methods (ENGINE)
//------------------------------------------------------------------------------
/**
* This method is automatically called once by the group manager when the group
* is created, or added. The method is public but should be considered
* internal. External calls should only be made if 1. The group is disabled, or
* 2. If the group is not added to a manager.
*
* @returns {undefined}
*/
rune.display.DisplayGroup.prototype.init = function() {
//@note: Override from sub class.
};
/**
* This method is called just before the group's update method and performs
* processes that must be completed before the group's main update process
* begins. Avoid overriding and modifying this method.
*
* @param {number} step Current time step.
*
* @returns {undefined}
*/
rune.display.DisplayGroup.prototype.preUpdate = function(step) {
this.m_updateArea(step);
this.m_updateQuadtree(step);
};
/**
* This method represents the group's main update process. The method can be
* overridden in order to add custom logic.
*
* @param {number} step Current time step.
*
* @returns {undefined}
*/
rune.display.DisplayGroup.prototype.update = function(step) {
//@note: Override from sub class.
};
/**
* This method is called automatically after the group's main update method is
* completed. The method can be overridden and used to complete closing
* processes just before the next update.
*
* @param {number} step Current time step.
*
* @returns {undefined}
*/
rune.display.DisplayGroup.prototype.postUpdate = function(step) {
//@note: Override from sub class.
};
/**
* This method is called automatically just before the group is destroyed.
* Override the method for creating your own deallocation code, ie code that
* deletes objects created by the group.
*
* @returns {undefined}
*/
rune.display.DisplayGroup.prototype.dispose = function() {
this.removeMembers(true);
this.m_disposeQuadtree();
};
//------------------------------------------------------------------------------
// Internal prototype methods
//------------------------------------------------------------------------------
/**
* Adds a new member to the group without adding it to the group container
* display list. Note that this method is internal and should therefore only
* be used by classes and objects within the display package.
*
* @param {rune.display.DisplayObject} member Display objects to add.
*
* @returns {boolean}
* @package
* @ignore
*/
rune.display.DisplayGroup.prototype.include = function(member) {
var index = this.m_members.indexOf(member);
if (index === -1) {
this.m_members.push(member);
member.setGroup(this);
return true;
}
return false;
};
/**
* Deletes a member from the group without removing it from the display list of
* the group's container object. Note that this method is internal and should
* therefore only be used by classes and objects within the display package.
*
* @param {rune.display.DisplayObject} member Display objects to remove.
*
* @returns {boolean}
* @package
* @ignore
*/
rune.display.DisplayGroup.prototype.exclude = function(member) {
var index = this.m_members.indexOf(member);
if (index > -1) {
this.m_members.splice(index, 1);
member.setGroup(null);
return true;
}
return false;
};
//------------------------------------------------------------------------------
// Private prototype methods
//------------------------------------------------------------------------------
/**
* Creates the group's internal quad tree.
*
* @throws {Error} If the object already exists.
*
* @returns {undefined}
* @private
*/
rune.display.DisplayGroup.prototype.m_constructQuadtree = function() {
this.m_disposeQuadtree();
if (this.m_quadtree == null) {
this.m_quadtree = new rune.display.Quadtree();
} else throw new Error();
};
/**
* Updates the group's internal quad tree.
*
* @param {number} step Current time step.
*
* @returns {undefined}
* @private
*/
rune.display.DisplayGroup.prototype.m_updateQuadtree = function(step) {
if (this.active == true && this.m_quadtree != null) {
var rect = this.getArea();
this.m_quadtree.clear();
this.m_quadtree.x = rect.x;
this.m_quadtree.y = rect.y;
this.m_quadtree.width = rect.width;
this.m_quadtree.height = rect.height;
var m = this.m_members;
var i = m.length;
while (i--) {
this.m_quadtree.insert(m[i]);
}
}
};
/**
* Updates the member area.
*
* @param {number} step Current time step.
*
* @returns {undefined}
* @private
*/
rune.display.DisplayGroup.prototype.m_updateArea = function(step) {
if (this.active == true) {
this.m_area = this.m_calculateArea(this.m_area);
}
};
/**
* Destroy the internal quad tree.
*
* @returns {undefined}
* @private
*/
rune.display.DisplayGroup.prototype.m_disposeQuadtree = function() {
if (this.m_quadtree instanceof rune.display.Quadtree) {
this.m_quadtree.clear();
this.m_quadtree = null;
}
};
/**
* Calculates the member area, ie the rectangular area within all group members can fit.
*
* @param {rune.geom.Rectangle} [rect] Rectangle to overwrite, if nothing is specified, a new rectangle object is returned.
*
* @returns {rune.geom.Rectangle}
* @private
*/
rune.display.DisplayGroup.prototype.m_calculateArea = function(rect) {
//@todo Does not work correctly within negative coordinates
rect = rect || new rune.geom.Rectangle();
var min = new rune.geom.Point(Number.MAX_VALUE, Number.MAX_VALUE);
var max = new rune.geom.Point(Number.MIN_VALUE, Number.MIN_VALUE);
var i = this.m_members.length;
if (i > 0) {
while (i--) {
min['x'] = Math.min(min['x'], this.m_members[i]['left']);
min['y'] = Math.min(min['y'], this.m_members[i]['top']);
max['x'] = Math.max(max['x'], this.m_members[i]['right']);
max['y'] = Math.max(max['y'], this.m_members[i]['bottom']);
}
} else {
min['x'] = 0;
min['y'] = 0;
max['x'] = 0;
max['y'] = 0;
}
rect['x'] = min['x'];
rect['y'] = min['y'];
rect['width'] = Math.abs(max['x'] - min['x']);
rect['height'] = Math.abs(max['y'] - min['y']);
return rect;
};</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="rune.html">rune</a></li><li><a href="rune.animation.html">animation</a></li><li><a href="rune.camera.html">camera</a></li><li><a href="rune.color.html">color</a></li><li><a href="rune.console.html">console</a></li><li><a href="rune.data.html">data</a></li><li><a href="rune.debug.html">debug</a></li><li><a href="rune.display.html">display</a></li><li><a href="rune.geom.html">geom</a></li><li><a href="rune.input.html">input</a></li><li><a href="rune.media.html">media</a></li><li><a href="rune.net.html">net</a></li><li><a href="rune.particle.html">particle</a></li><li><a href="rune.physics.html">physics</a></li><li><a href="rune.resource.html">resource</a></li><li><a href="rune.scene.html">scene</a></li><li><a href="rune.state.html">state</a></li><li><a href="rune.system.html">system</a></li><li><a href="rune.text.html">text</a></li><li><a href="rune.tilemap.html">tilemap</a></li><li><a href="rune.timer.html">timer</a></li><li><a href="rune.tween.html">tween</a></li><li><a href="rune.ui.html">ui</a></li><li><a href="rune.util.html">util</a></li></ul><h3>Classes</h3><ul><li><a href="rune.animation.Animation.html">Animation</a></li><li><a href="rune.animation.Animations.html">Animations</a></li><li><a href="rune.animation.AnimationScripts.html">AnimationScripts</a></li><li><a href="rune.camera.Camera.html">Camera</a></li><li><a href="rune.camera.CameraFade.html">CameraFade</a></li><li><a href="rune.camera.CameraFlash.html">CameraFlash</a></li><li><a href="rune.camera.Cameras.html">Cameras</a></li><li><a href="rune.camera.CameraShake.html">CameraShake</a></li><li><a href="rune.camera.CameraTargets.html">CameraTargets</a></li><li><a href="rune.camera.CameraTint.html">CameraTint</a></li><li><a href="rune.camera.CameraTintTween.html">CameraTintTween</a></li><li><a href="rune.camera.CameraViewport.html">CameraViewport</a></li><li><a href="rune.color.Color24.html">Color24</a></li><li><a href="rune.color.Color32.html">Color32</a></li><li><a href="rune.color.ColorComponent.html">ColorComponent</a></li><li><a href="rune.console.Console.html">Console</a></li><li><a href="rune.console.ConsoleCommand.html">ConsoleCommand</a></li><li><a href="rune.console.ConsoleCommands.html">ConsoleCommands</a></li><li><a href="rune.console.ConsoleCursor.html">ConsoleCursor</a></li><li><a href="rune.console.ConsoleHistory.html">ConsoleHistory</a></li><li><a href="rune.console.ConsoleInput.html">ConsoleInput</a></li><li><a href="rune.console.ConsoleManager.html">ConsoleManager</a></li><li><a href="rune.console.ConsoleOutput.html">ConsoleOutput</a></li><li><a href="rune.data.Highscores.html">Highscores</a></li><li><a href="rune.data.Loader.html">Loader</a></li><li><a href="rune.data.LoaderDebug.html">LoaderDebug</a></li><li><a href="rune.data.Logo.html">Logo</a></li><li><a href="rune.data.Requests.html">Requests</a></li><li><a href="rune.debug.Debugger.html">Debugger</a></li><li><a href="rune.debug.Framerate.html">Framerate</a></li><li><a href="rune.debug.Histogram.html">Histogram</a></li><li><a href="rune.debug.Master.html">Master</a></li><li><a href="rune.debug.Memory.html">Memory</a></li><li><a href="rune.debug.Music.html">Music</a></li><li><a href="rune.debug.Render.html">Render</a></li><li><a href="rune.debug.Sound.html">Sound</a></li><li><a href="rune.debug.Update.html">Update</a></li><li><a href="rune.display.Artboard.html">Artboard</a></li><li><a href="rune.display.Canvas.html">Canvas</a></li><li><a href="rune.display.DisplayGroup.html">DisplayGroup</a></li><li><a href="rune.display.DisplayGroups.html">DisplayGroups</a></li><li><a href="rune.display.DisplayObject.html">DisplayObject</a></li><li><a href="rune.display.DisplayObjectContainer.html">DisplayObjectContainer</a></li><li><a href="rune.display.Flicker.html">Flicker</a></li><li><a href="rune.display.Frame.html">Frame</a></li><li><a href="rune.display.Graphic.html">Graphic</a></li><li><a href="rune.display.Graphics.html">Graphics</a></li><li><a href="rune.display.Hitbox.html">Hitbox</a></li><li><a href="rune.display.InteractiveObject.html">InteractiveObject</a></li><li><a href="rune.display.Quadtree.html">Quadtree</a></li><li><a href="rune.display.RepeatedGraphic.html">RepeatedGraphic</a></li><li><a href="rune.display.Screen.html">Screen</a></li><li><a href="rune.display.Sprite.html">Sprite</a></li><li><a href="rune.display.Stage.html">Stage</a></li><li><a href="rune.display.Texture.html">Texture</a></li><li><a href="rune.geom.Point.html">Point</a></li><li><a href="rune.geom.Rectangle.html">Rectangle</a></li><li><a href="rune.geom.Vector2D.html">Vector2D</a></li><li><a href="rune.input.Gamepad.html">Gamepad</a></li><li><a href="rune.input.Gamepads.html">Gamepads</a></li><li><a href="rune.input.GamepadsOptions.html">GamepadsOptions</a></li><li><a href="rune.input.Inputs.html">Inputs</a></li><li><a href="rune.input.Keyboard.html">Keyboard</a></li><li><a href="rune.input.KeyboardKey.html">KeyboardKey</a></li><li><a href="rune.input.KeyboardOptions.html">KeyboardOptions</a></li><li><a href="rune.media.Sound.html">Sound</a></li><li><a href="rune.media.SoundChannel.html">SoundChannel</a></li><li><a href="rune.media.Sounds.html">Sounds</a></li><li><a href="rune.net.URLLoader.html">URLLoader</a></li><li><a href="rune.net.URLRequest.html">URLRequest</a></li><li><a href="rune.net.URLResponse.html">URLResponse</a></li><li><a href="rune.particle.Emitter.html">Emitter</a></li><li><a href="rune.particle.EmitterOptions.html">EmitterOptions</a></li><li><a href="rune.particle.Particle.html">Particle</a></li><li><a href="rune.physics.Space.html">Space</a></li><li><a href="rune.physics.Velocity.html">Velocity</a></li><li><a href="rune.resource.Request.html">Request</a></li><li><a href="rune.resource.Requester.html">Requester</a></li><li><a href="rune.resource.RequesterOptions.html">RequesterOptions</a></li><li><a href="rune.resource.Requests.html">Requests</a></li><li><a href="rune.resource.Resource.html">Resource</a></li><li><a href="rune.resource.Resources.html">Resources</a></li><li><a href="rune.scene.Scene.html">Scene</a></li><li><a href="rune.scene.Scenes.html">Scenes</a></li><li><a href="rune.state.State.html">State</a></li><li><a href="rune.state.States.html">States</a></li><li><a href="rune.system.Application.html">Application</a></li><li><a href="rune.system.Config.html">Config</a></li><li><a href="rune.system.Time.html">Time</a></li><li><a href="rune.text.BitmapField.html">BitmapField</a></li><li><a href="rune.text.BitmapFormat.html">BitmapFormat</a></li><li><a href="rune.tilemap.Block.html">Block</a></li><li><a href="rune.tilemap.Tile.html">Tile</a></li><li><a href="rune.tilemap.Tilemap.html">Tilemap</a></li><li><a href="rune.tilemap.TilemapLayer.html">TilemapLayer</a></li><li><a href="rune.timer.Timer.html">Timer</a></li><li><a href="rune.timer.TimerOptions.html">TimerOptions</a></li><li><a href="rune.timer.Timers.html">Timers</a></li><li><a href="rune.tween.Circular.html">Circular</a></li><li><a href="rune.tween.Cubic.html">Cubic</a></li><li><a href="rune.tween.Expo.html">Expo</a></li><li><a href="rune.tween.Linear.html">Linear</a></li><li><a href="rune.tween.Quad.html">Quad</a></li><li><a href="rune.tween.Quart.html">Quart</a></li><li><a href="rune.tween.Quint.html">Quint</a></li><li><a href="rune.tween.Sine.html">Sine</a></li><li><a href="rune.tween.Tween.html">Tween</a></li><li><a href="rune.tween.Tweens.html">Tweens</a></li><li><a href="rune.tween.TweenValue.html">TweenValue</a></li><li><a href="rune.ui.Counter.html">Counter</a></li><li><a href="rune.ui.CounterDigit.html">CounterDigit</a></li><li><a href="rune.ui.Progressbar.html">Progressbar</a></li><li><a href="rune.ui.VTList.html">VTList</a></li><li><a href="rune.ui.VTListElement.html">VTListElement</a></li><li><a href="rune.ui.VTMenu.html">VTMenu</a></li><li><a href="rune.ui.VTMenuPointer.html">VTMenuPointer</a></li><li><a href="rune.util.Executable.html">Executable</a></li><li><a href="rune.util.Filter.html">Filter</a></li><li><a href="rune.util.Math.html">Math</a></li><li><a href="rune.util.Palette.html">Palette</a></li><li><a href="rune.util.Path.html">Path</a></li><li><a href="rune.util.Paths.html">Paths</a></li><li><a href="rune.util.Stack.html">Stack</a></li><li><a href="rune.util.URL.html">URL</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Tue May 21 2024 09:43:50 GMT+0200 (Central European Summer Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>