From edf93b57954d943368b5bba9a3c187a455101050 Mon Sep 17 00:00:00 2001 From: Gama11 Date: Sun, 21 Aug 2016 16:05:48 +0200 Subject: [PATCH] CameraFrontEnd: add added / removed / resized signals Necessary to fix #1801, and probably otherwise useful as well. --- flixel/FlxCamera.hx | 8 ++++++-- flixel/system/debug/log/BitmapLog.hx | 1 - flixel/system/frontEnds/CameraFrontEnd.hx | 24 +++++++++++++---------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index c40538743c..908c97a7b9 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -1547,26 +1547,30 @@ class FlxCamera extends FlxBasic private function set_width(Value:Int):Int { - if (Value > 0) + if (width != Value && Value > 0) { width = Value; updateFlashOffset(); updateScrollRect(); updateInternalSpritePositions(); + + FlxG.cameras.cameraResized.dispatch(this); } return Value; } private function set_height(Value:Int):Int { - if (Value > 0) + if (height != Value && Value > 0) { height = Value; updateFlashOffset(); updateScrollRect(); updateInternalSpritePositions(); + + FlxG.cameras.cameraResized.dispatch(this); } return Value; } diff --git a/flixel/system/debug/log/BitmapLog.hx b/flixel/system/debug/log/BitmapLog.hx index 876227870e..f44e29900c 100644 --- a/flixel/system/debug/log/BitmapLog.hx +++ b/flixel/system/debug/log/BitmapLog.hx @@ -246,7 +246,6 @@ class BitmapLog extends Window /** * Clear one bitmap object from the log -- the last one, by default - * @param Index */ public function clearAt(Index:Int = -1):Void { diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index e8ae1c7237..afbf2fe7dc 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -5,6 +5,7 @@ import flixel.FlxCamera; import flixel.FlxG; import flixel.util.FlxAxes; import flixel.util.FlxColor; +import flixel.util.FlxSignal.FlxTypedSignal; class CameraFrontEnd { @@ -19,6 +20,12 @@ class CameraFrontEnd */ public var bgColor(get, set):FlxColor; + public var cameraAdded(default, null):FlxTypedSignalVoid> = new FlxTypedSignalVoid>(); + + public var cameraRemoved(default, null):FlxTypedSignalVoid> = new FlxTypedSignalVoid>(); + + public var cameraResized(default, null):FlxTypedSignalVoid> = new FlxTypedSignalVoid>(); + /** * Allows you to possibly slightly optimize the rendering process IF * you are not doing any pre-processing in your game state's draw() call. @@ -41,6 +48,7 @@ class CameraFrontEnd FlxG.game.addChildAt(NewCamera.flashSprite, FlxG.game.getChildIndex(FlxG.game._inputContainer)); FlxG.cameras.list.push(NewCamera); NewCamera.ID = FlxG.cameras.list.length - 1; + cameraAdded.dispatch(NewCamera); return NewCamera; } @@ -53,14 +61,15 @@ class CameraFrontEnd public function remove(Camera:FlxCamera, Destroy:Bool = true):Void { var index:Int = list.indexOf(Camera); - if ((Camera != null) && index != -1) + if (Camera != null && index != -1) { FlxG.game.removeChild(Camera.flashSprite); list.splice(index, 1); } else { - FlxG.log.warn("FlxG.cameras.remove(): The camera you attemped to remove is not a part of the game."); + FlxG.log.warn("FlxG.cameras.remove(): The camera you attempted to remove is not a part of the game."); + return; } if (FlxG.renderTile) @@ -72,9 +81,9 @@ class CameraFrontEnd } if (Destroy) - { Camera.destroy(); - } + + cameraRemoved.dispatch(Camera); } /** @@ -86,17 +95,12 @@ class CameraFrontEnd public function reset(?NewCamera:FlxCamera):Void { for (camera in list) - { - FlxG.game.removeChild(camera.flashSprite); - camera.destroy(); - } + remove(camera); list.splice(0, list.length); if (NewCamera == null) - { NewCamera = new FlxCamera(0, 0, FlxG.width, FlxG.height); - } FlxG.camera = add(NewCamera); NewCamera.ID = 0;