From 34c6901001b153ffaf22593927bf3c6af000c0f8 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:39:23 +0200 Subject: [PATCH 1/4] FlxGame: implement camera container --- flixel/FlxGame.hx | 10 +++++++++- flixel/system/frontEnds/CameraFrontEnd.hx | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index 6f9eb08b3b..c3043aca92 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -156,9 +156,15 @@ class FlxGame extends Sprite * Mouse cursor. */ @:allow(flixel.FlxG) - @:allow(flixel.system.frontEnds.CameraFrontEnd) var _inputContainer:Sprite; + /** + * All cameras' sprites are added here to make it easier to + * do things such as applying a filter to the entire game view. + */ + @:allow(flixel.system.frontEnds.CameraFrontEnd) + var _cameraContainer:Sprite; + #if FLX_SOUND_TRAY /** * Change this after calling `super()` in the `FlxGame` constructor @@ -250,6 +256,7 @@ class FlxGame extends Sprite // Super high priority init stuff _inputContainer = new Sprite(); + _cameraContainer = new Sprite(); if (gameWidth == 0) gameWidth = FlxG.stage.stageWidth; @@ -305,6 +312,7 @@ class FlxGame extends Sprite stage.frameRate = FlxG.drawFramerate; addChild(_inputContainer); + addChild(_cameraContainer); // Creating the debugger overlay #if FLX_DEBUG diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index 965d0eff3d..fabfdf89ad 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -64,8 +64,8 @@ class CameraFrontEnd */ public function add(NewCamera:T, DefaultDrawTarget:Bool = true):T { - FlxG.game.addChildAt(NewCamera.flashSprite, FlxG.game.getChildIndex(FlxG.game._inputContainer)); - + FlxG.game._cameraContainer.addChildAt(NewCamera.flashSprite, 0); + list.push(NewCamera); if (DefaultDrawTarget) defaults.push(NewCamera); From aeed74015a8141efe03a29f939a7fef8f35a1f87 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:41:09 +0200 Subject: [PATCH 2/4] FlxGame: apply filters to game view instead of all children --- flixel/FlxGame.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index c3043aca92..7125589ccc 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -717,7 +717,7 @@ class FlxGame extends Sprite } #end - filters = filtersEnabled ? _filters : null; + _cameraContainer.filters = filtersEnabled ? _filters : null; } function updateElapsed():Void From 90765e2ec818688d92cd30f1bb5964f070345398 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:44:47 +0200 Subject: [PATCH 3/4] CameraFrontEnd: fix add/insert/remove logic --- flixel/FlxGame.hx | 4 ++-- flixel/system/frontEnds/CameraFrontEnd.hx | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index 7125589ccc..9c3769bfef 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -255,8 +255,8 @@ class FlxGame extends Sprite #end // Super high priority init stuff - _inputContainer = new Sprite(); _cameraContainer = new Sprite(); + _inputContainer = new Sprite(); if (gameWidth == 0) gameWidth = FlxG.stage.stageWidth; @@ -311,8 +311,8 @@ class FlxGame extends Sprite stage.align = StageAlign.TOP_LEFT; stage.frameRate = FlxG.drawFramerate; - addChild(_inputContainer); addChild(_cameraContainer); + addChild(_inputContainer); // Creating the debugger overlay #if FLX_DEBUG diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index fabfdf89ad..6f17bf7759 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -64,7 +64,7 @@ class CameraFrontEnd */ public function add(NewCamera:T, DefaultDrawTarget:Bool = true):T { - FlxG.game._cameraContainer.addChildAt(NewCamera.flashSprite, 0); + FlxG.game._cameraContainer.addChild(newCamera.flashSprite); list.push(NewCamera); if (DefaultDrawTarget) @@ -97,8 +97,8 @@ class CameraFrontEnd if (position >= list.length) return add(newCamera); - final childIndex = FlxG.game.getChildIndex(list[position].flashSprite); - FlxG.game.addChildAt(newCamera.flashSprite, childIndex); + final childIndex = FlxG.game._cameraContainer.getChildIndex(list[position].flashSprite); + FlxG.game._cameraContainer.addChildAt(newCamera.flashSprite, childIndex); list.insert(position, newCamera); if (defaultDrawTarget) @@ -122,7 +122,7 @@ class CameraFrontEnd var index:Int = list.indexOf(Camera); if (Camera != null && index != -1) { - FlxG.game.removeChild(Camera.flashSprite); + FlxG.game._cameraContainer.removeChild(Camera.flashSprite); list.splice(index, 1); defaults.remove(Camera); } From 60cf6c446ed523cc00372f373cb4fbe0d1196a43 Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 15 Sep 2025 21:32:50 +0200 Subject: [PATCH 4/4] CameraFrontEnd: lowercase args --- flixel/system/frontEnds/CameraFrontEnd.hx | 96 +++++++++++------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index 6f17bf7759..0959637dc8 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -57,22 +57,22 @@ class CameraFrontEnd * Handy for PiP, split-screen, etc. * @see flixel.FlxBasic.cameras * - * @param NewCamera The camera you want to add. - * @param DefaultDrawTarget Whether to add the camera to the list of default draw targets. If false, + * @param newCamera The camera you want to add. + * @param defaultDrawTarget Whether to add the camera to the list of default draw targets. If false, * `FlxBasics` will not render to it unless you add it to their `cameras` list. * @return This FlxCamera instance. */ - public function add(NewCamera:T, DefaultDrawTarget:Bool = true):T + public function add(newCamera:T, defaultDrawTarget:Bool = true):T { FlxG.game._cameraContainer.addChild(newCamera.flashSprite); - list.push(NewCamera); - if (DefaultDrawTarget) - defaults.push(NewCamera); + list.push(newCamera); + if (defaultDrawTarget) + defaults.push(newCamera); - NewCamera.ID = list.length - 1; - cameraAdded.dispatch(NewCamera); - return NewCamera; + newCamera.ID = list.length - 1; + cameraAdded.dispatch(newCamera); + return newCamera; } /** @@ -114,17 +114,17 @@ class CameraFrontEnd /** * Remove a camera from the game. * - * @param Camera The camera you want to remove. - * @param Destroy Whether to call destroy() on the camera, default value is true. + * @param camera The camera you want to remove. + * @param destroy Whether to call destroy() on the camera, default value is true. */ - public function remove(Camera:FlxCamera, Destroy:Bool = true):Void + public function remove(camera:FlxCamera, destroy:Bool = true):Void { - var index:Int = list.indexOf(Camera); - if (Camera != null && index != -1) + var index:Int = list.indexOf(camera); + if (camera != null && index != -1) { - FlxG.game._cameraContainer.removeChild(Camera.flashSprite); + FlxG.game._cameraContainer.removeChild(camera.flashSprite); list.splice(index, 1); - defaults.remove(Camera); + defaults.remove(camera); } else { @@ -140,10 +140,10 @@ class CameraFrontEnd } } - if (Destroy) - Camera.destroy(); + if (destroy) + camera.destroy(); - cameraRemoved.dispatch(Camera); + cameraRemoved.dispatch(camera); } /** @@ -175,20 +175,20 @@ class CameraFrontEnd * Dumps all the current cameras and resets to just one camera. * Handy for doing split-screen especially. * - * @param NewCamera Optional; specify a specific camera object to be the new main camera. + * @param newCamera Optional; specify a specific camera object to be the new main camera. */ - public function reset(?NewCamera:FlxCamera):Void + public function reset(?newCamera:FlxCamera):Void { FlxG.camera = null; while (list.length > 0) remove(list[0]); - if (NewCamera == null) - NewCamera = new FlxCamera(); + if (newCamera == null) + newCamera = new FlxCamera(); - FlxG.camera = add(NewCamera); - NewCamera.ID = 0; + FlxG.camera = add(newCamera); + newCamera.ID = 0; FlxCamera._defaultCameras = defaults; } @@ -196,50 +196,50 @@ class CameraFrontEnd /** * All screens are filled with this color and gradually return to normal. * - * @param Color The color you want to use. - * @param Duration How long it takes for the flash to fade. - * @param OnComplete A function you want to run when the flash finishes. - * @param Force Force the effect to reset. + * @param color The color you want to use. + * @param duration How long it takes for the flash to fade. + * @param onComplete A function you want to run when the flash finishes. + * @param force Force the effect to reset. */ - public function flash(Color:FlxColor = FlxColor.WHITE, Duration:Float = 1, ?OnComplete:Void->Void, Force:Bool = false):Void + public function flash(color:FlxColor = FlxColor.WHITE, duration:Float = 1, ?onComplete:Void->Void, force:Bool = false):Void { for (camera in list) { - camera.flash(Color, Duration, OnComplete, Force); + camera.flash(color, duration, onComplete, force); } } /** * The screen is gradually filled with this color. * - * @param Color The color you want to use. - * @param Duration How long it takes for the fade to finish. - * @param FadeIn True fades from a color, false fades to it. - * @param OnComplete A function you want to run when the fade finishes. - * @param Force Force the effect to reset. + * @param color The color you want to use. + * @param duration How long it takes for the fade to finish. + * @param fadeIn True fades from a color, false fades to it. + * @param onComplete A function you want to run when the fade finishes. + * @param force Force the effect to reset. */ - public function fade(Color:FlxColor = FlxColor.BLACK, Duration:Float = 1, FadeIn:Bool = false, ?OnComplete:Void->Void, Force:Bool = false):Void + public function fade(color:FlxColor = FlxColor.BLACK, duration:Float = 1, fadeIn:Bool = false, ?onComplete:Void->Void, force:Bool = false):Void { for (camera in list) { - camera.fade(Color, Duration, FadeIn, OnComplete, Force); + camera.fade(color, duration, fadeIn, onComplete, force); } } /** * A simple screen-shake effect. * - * @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking. - * @param Duration The length in seconds that the shaking effect should last. - * @param OnComplete A function you want to run when the shake effect finishes. - * @param Force Force the effect to reset (default = true, unlike flash() and fade()!). - * @param Axes On what axes to shake. Default value is XY / both. + * @param intensity Percentage of screen size representing the maximum distance that the screen can move while shaking. + * @param duration The length in seconds that the shaking effect should last. + * @param onComplete A function you want to run when the shake effect finishes. + * @param force Force the effect to reset (default = true, unlike flash() and fade()!). + * @param axes On what axes to shake. Default value is XY / both. */ - public function shake(Intensity:Float = 0.05, Duration:Float = 0.5, ?OnComplete:Void->Void, Force:Bool = true, ?Axes:FlxAxes):Void + public function shake(intensity:Float = 0.05, duration:Float = 0.5, ?onComplete:Void->Void, force:Bool = true, ?axes:FlxAxes):Void { for (camera in list) { - camera.shake(Intensity, Duration, OnComplete, Force, Axes); + camera.shake(intensity, duration, onComplete, force, axes); } } @@ -368,13 +368,13 @@ class CameraFrontEnd return (FlxG.camera == null) ? FlxColor.BLACK : FlxG.camera.bgColor; } - function set_bgColor(Color:FlxColor):FlxColor + function set_bgColor(color:FlxColor):FlxColor { for (camera in list) { - camera.bgColor = Color; + camera.bgColor = color; } - return Color; + return color; } }