Skip to content

Commit 84c1344

Browse files
committed
CameraManager.getVisibleChildren is a new method that is called internally by the CameraManager.render method. It filters the DisplayList, so that Game Objects that pass the willRender test for the given Camera are added to a sub-list, which is then passed to the renderer. This avoids the renderer having to do any checks on the children, it just renders each one in turn.
1 parent 653c2ee commit 84c1344

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

src/cameras/2d/CameraManager.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ var CameraManager = new Class({
583583
* @since 3.0.0
584584
*
585585
* @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The Renderer that will render the children to this camera.
586-
* @param {Phaser.GameObjects.GameObject[]} children - An array of renderable Game Objects.
586+
* @param {Phaser.GameObjects.DisplayList} children - The Display List for the Scene.
587587
*/
588588
render: function (renderer, children)
589589
{
@@ -596,12 +596,43 @@ var CameraManager = new Class({
596596

597597
if (camera.visible && camera.alpha > 0)
598598
{
599-
// Hard-coded to 1 for now
600-
camera.preRender(1);
599+
camera.preRender();
601600

602-
renderer.render(scene, children, camera);
601+
var visibleChildren = this.getVisibleChildren(children.getChildren(), camera);
602+
603+
renderer.render(scene, visibleChildren, camera);
604+
}
605+
}
606+
},
607+
608+
/**
609+
* Takes an array of Game Objects and a Camera and returns a new array
610+
* containing only those Game Objects that pass the `willRender` test
611+
* against the given Camera.
612+
*
613+
* @method Phaser.Cameras.Scene2D.CameraManager#getVisibleChildren
614+
* @since 3.50.0
615+
*
616+
* @param {Phaser.GameObjects.GameObject[]} children - An array of Game Objects to be checked against the camera.
617+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera to filte the Game Objects against.
618+
*
619+
* @return {Phaser.GameObjects.GameObject[]} A filtered list of only Game Objects within the Scene that will render against the given Camera.
620+
*/
621+
getVisibleChildren: function (children, camera)
622+
{
623+
var visible = [];
624+
625+
for (var i = 0; i < children.length; i++)
626+
{
627+
var child = children[i];
628+
629+
if (child.willRender(camera))
630+
{
631+
visible.push(child);
603632
}
604633
}
634+
635+
return visible;
605636
},
606637

607638
/**

0 commit comments

Comments
 (0)