Skip to content

Commit

Permalink
CameraFrontEnd: add added / removed / resized signals
Browse files Browse the repository at this point in the history
Necessary to fix #1801, and probably otherwise useful as well.
  • Loading branch information
Gama11 committed Aug 21, 2016
1 parent 500e7a8 commit edf93b5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
8 changes: 6 additions & 2 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion flixel/system/debug/log/BitmapLog.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
24 changes: 14 additions & 10 deletions flixel/system/frontEnds/CameraFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -19,6 +20,12 @@ class CameraFrontEnd
*/
public var bgColor(get, set):FlxColor;

public var cameraAdded(default, null):FlxTypedSignal<FlxCamera->Void> = new FlxTypedSignal<FlxCamera->Void>();

public var cameraRemoved(default, null):FlxTypedSignal<FlxCamera->Void> = new FlxTypedSignal<FlxCamera->Void>();

public var cameraResized(default, null):FlxTypedSignal<FlxCamera->Void> = new FlxTypedSignal<FlxCamera->Void>();

/**
* Allows you to possibly slightly optimize the rendering process IF
* you are not doing any pre-processing in your game state's draw() call.
Expand All @@ -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;
}

Expand All @@ -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)
Expand All @@ -72,9 +81,9 @@ class CameraFrontEnd
}

if (Destroy)
{
Camera.destroy();
}

cameraRemoved.dispatch(Camera);
}

/**
Expand All @@ -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;
Expand Down

0 comments on commit edf93b5

Please sign in to comment.