Skip to content

Commit bf2af95

Browse files
committed
CameraManager.getCameraBelowPointer has been renamed to getCamerasBelowPointer and it now returns an array of all the cameras below the given pointer, not just the top-most one. The array is sorted so that the top-most camera is at the start of the array.
1 parent 719a2ee commit bf2af95

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

src/cameras/2d/CameraManager.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ var CameraManager = new Class({
240240
{
241241
this.cameras.push(camera);
242242
this.cameraPool.slice(poolIndex, 1);
243+
243244
return camera;
244245
}
245246

@@ -284,6 +285,7 @@ var CameraManager = new Class({
284285
camera.scrollX = GetFastValue(cameraConfig, 'scrollX', 0);
285286
camera.scrollY = GetFastValue(cameraConfig, 'scrollY', 0);
286287
camera.roundPixels = GetFastValue(cameraConfig, 'roundPixels', false);
288+
camera.visible = GetFastValue(cameraConfig, 'visible', true);
287289

288290
// Background Color
289291

@@ -336,29 +338,38 @@ var CameraManager = new Class({
336338
},
337339

338340
/**
339-
* [description]
341+
* Returns an array of all cameras below the given Pointer.
342+
*
343+
* The first camera in the array is the top-most camera in the camera list.
340344
*
341-
* @method Phaser.Cameras.Scene2D.CameraManager#getCameraBelowPointer
342-
* @since 3.0.0
345+
* @method Phaser.Cameras.Scene2D.CameraManager#getCamerasBelowPointer
346+
* @since 3.10.0
343347
*
344-
* @param {Phaser.Input.Pointer} pointer - [description]
348+
* @param {Phaser.Input.Pointer} pointer - The Pointer to check against.
345349
*
346-
* @return {Phaser.Cameras.Scene2D.Camera} [description]
350+
* @return {Phaser.Cameras.Scene2D.Camera[]} An array of cameras below the Pointer.
347351
*/
348-
getCameraBelowPointer: function (pointer)
352+
getCamerasBelowPointer: function (pointer)
349353
{
350354
var cameras = this.cameras;
351355

352-
// Start from the most recently added camera (the 'top' camera)
353-
for (var i = cameras.length - 1; i >= 0; i--)
356+
var x = pointer.x;
357+
var y = pointer.y;
358+
359+
var output = [];
360+
361+
for (var i = 0; i < cameras.length; i++)
354362
{
355363
var camera = cameras[i];
356364

357-
if (camera.inputEnabled && RectangleContains(camera, pointer.x, pointer.y))
365+
if (camera.visible && camera.inputEnabled && RectangleContains(camera, x, y))
358366
{
359-
return camera;
367+
// So the top-most camera is at the top of the search array
368+
output.unshift(camera);
360369
}
361370
}
371+
372+
return output;
362373
},
363374

364375
/**
@@ -404,9 +415,12 @@ var CameraManager = new Class({
404415
{
405416
var camera = cameras[i];
406417

407-
camera.preRender(baseScale, renderer.config.resolution);
418+
if (camera.visible)
419+
{
420+
camera.preRender(baseScale, renderer.config.resolution);
408421

409-
renderer.render(this.scene, children, interpolation, camera);
422+
renderer.render(this.scene, children, interpolation, camera);
423+
}
410424
}
411425
},
412426

0 commit comments

Comments
 (0)