Skip to content

Commit edf93b5

Browse files
committed
CameraFrontEnd: add added / removed / resized signals
Necessary to fix #1801, and probably otherwise useful as well.
1 parent 500e7a8 commit edf93b5

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

flixel/FlxCamera.hx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,26 +1547,30 @@ class FlxCamera extends FlxBasic
15471547

15481548
private function set_width(Value:Int):Int
15491549
{
1550-
if (Value > 0)
1550+
if (width != Value && Value > 0)
15511551
{
15521552
width = Value;
15531553

15541554
updateFlashOffset();
15551555
updateScrollRect();
15561556
updateInternalSpritePositions();
1557+
1558+
FlxG.cameras.cameraResized.dispatch(this);
15571559
}
15581560
return Value;
15591561
}
15601562

15611563
private function set_height(Value:Int):Int
15621564
{
1563-
if (Value > 0)
1565+
if (height != Value && Value > 0)
15641566
{
15651567
height = Value;
15661568

15671569
updateFlashOffset();
15681570
updateScrollRect();
15691571
updateInternalSpritePositions();
1572+
1573+
FlxG.cameras.cameraResized.dispatch(this);
15701574
}
15711575
return Value;
15721576
}

flixel/system/debug/log/BitmapLog.hx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ class BitmapLog extends Window
246246

247247
/**
248248
* Clear one bitmap object from the log -- the last one, by default
249-
* @param Index
250249
*/
251250
public function clearAt(Index:Int = -1):Void
252251
{

flixel/system/frontEnds/CameraFrontEnd.hx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import flixel.FlxCamera;
55
import flixel.FlxG;
66
import flixel.util.FlxAxes;
77
import flixel.util.FlxColor;
8+
import flixel.util.FlxSignal.FlxTypedSignal;
89

910
class CameraFrontEnd
1011
{
@@ -19,6 +20,12 @@ class CameraFrontEnd
1920
*/
2021
public var bgColor(get, set):FlxColor;
2122

23+
public var cameraAdded(default, null):FlxTypedSignal<FlxCamera->Void> = new FlxTypedSignal<FlxCamera->Void>();
24+
25+
public var cameraRemoved(default, null):FlxTypedSignal<FlxCamera->Void> = new FlxTypedSignal<FlxCamera->Void>();
26+
27+
public var cameraResized(default, null):FlxTypedSignal<FlxCamera->Void> = new FlxTypedSignal<FlxCamera->Void>();
28+
2229
/**
2330
* Allows you to possibly slightly optimize the rendering process IF
2431
* you are not doing any pre-processing in your game state's draw() call.
@@ -41,6 +48,7 @@ class CameraFrontEnd
4148
FlxG.game.addChildAt(NewCamera.flashSprite, FlxG.game.getChildIndex(FlxG.game._inputContainer));
4249
FlxG.cameras.list.push(NewCamera);
4350
NewCamera.ID = FlxG.cameras.list.length - 1;
51+
cameraAdded.dispatch(NewCamera);
4452
return NewCamera;
4553
}
4654

@@ -53,14 +61,15 @@ class CameraFrontEnd
5361
public function remove(Camera:FlxCamera, Destroy:Bool = true):Void
5462
{
5563
var index:Int = list.indexOf(Camera);
56-
if ((Camera != null) && index != -1)
64+
if (Camera != null && index != -1)
5765
{
5866
FlxG.game.removeChild(Camera.flashSprite);
5967
list.splice(index, 1);
6068
}
6169
else
6270
{
63-
FlxG.log.warn("FlxG.cameras.remove(): The camera you attemped to remove is not a part of the game.");
71+
FlxG.log.warn("FlxG.cameras.remove(): The camera you attempted to remove is not a part of the game.");
72+
return;
6473
}
6574

6675
if (FlxG.renderTile)
@@ -72,9 +81,9 @@ class CameraFrontEnd
7281
}
7382

7483
if (Destroy)
75-
{
7684
Camera.destroy();
77-
}
85+
86+
cameraRemoved.dispatch(Camera);
7887
}
7988

8089
/**
@@ -86,17 +95,12 @@ class CameraFrontEnd
8695
public function reset(?NewCamera:FlxCamera):Void
8796
{
8897
for (camera in list)
89-
{
90-
FlxG.game.removeChild(camera.flashSprite);
91-
camera.destroy();
92-
}
98+
remove(camera);
9399

94100
list.splice(0, list.length);
95101

96102
if (NewCamera == null)
97-
{
98103
NewCamera = new FlxCamera(0, 0, FlxG.width, FlxG.height);
99-
}
100104

101105
FlxG.camera = add(NewCamera);
102106
NewCamera.ID = 0;

0 commit comments

Comments
 (0)