Skip to content

Commit 1bfe58a

Browse files
committed
remove can take an array of cameras and also no longer needs total to be > 0
1 parent 183f5c4 commit 1bfe58a

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* `CameraManager.addExisting` no longer needs to be passed a Camera that already exists in the pool (as the pool has been removed), meaning you can now create your own Cameras and pass them to `addExisting` and have them treated as normal cameras and not be ignored by the manager. They are also assigned a proper ID when added.
2525
* `CameraManager.addExisting` has a new boolean argument `makeMain` which will make the new camera the main one.
2626
* `CameraManager.getTotal` is a new method that will return the total number of Cameras being managed, with an optional `isVisible` argument, that only counts visible cameras if set.
27+
* `CameraManager.remove` can now take an array of cameras to be removed from the manager, as well as a single camera.
28+
* `CameraManager.remove` would previously not allow you to remove a camera if it meant there would be no cameras left in the Camera Manager. This restriction has been removed. A Camera Manager can now run even with zero cameras. Your game obviously won't display anything, but it's still now possible.
2729

2830
### New Features
2931

src/cameras/2d/CameraManager.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ var CameraManager = new Class({
492492
},
493493

494494
/**
495-
* Removes the given Camera from this Camera Manager.
495+
* Removes the given Camera, or an array of Cameras, from this Camera Manager.
496496
*
497497
* If found in the Camera Manager it will be immediately removed from the local cameras array.
498498
* If also currently the 'main' camera, 'main' will be reset to be camera 0.
@@ -503,21 +503,32 @@ var CameraManager = new Class({
503503
* @method Phaser.Cameras.Scene2D.CameraManager#remove
504504
* @since 3.0.0
505505
*
506-
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to be removed from this Camera Manager.
506+
* @param {(Phaser.Cameras.Scene2D.Camera|Phaser.Cameras.Scene2D.Camera[])} camera - The Camera, or an array of Cameras, to be removed from this Camera Manager.
507507
*/
508508
remove: function (camera)
509509
{
510-
var cameraIndex = this.cameras.indexOf(camera);
510+
if (!Array.isArray(camera))
511+
{
512+
camera = [ camera ];
513+
}
511514

512-
if (cameraIndex >= 0 && this.cameras.length > 1)
515+
var cameras = this.cameras;
516+
517+
for (var i = 0; i < camera.length; i++)
513518
{
514-
this.cameras.splice(cameraIndex, 1);
519+
var index = cameras.indexOf(camera);
515520

516-
if (this.main === camera)
521+
if (index !== -1)
517522
{
518-
this.main = this.cameras[0];
523+
cameras.splice(index, 1);
524+
519525
}
520526
}
527+
528+
if (!this.main)
529+
{
530+
this.main = this.cameras[0];
531+
}
521532
},
522533

523534
/**

0 commit comments

Comments
 (0)