Custom Camera System crashing
-
Hi,
I have a simple custom camera system which simply switches the between cameras for normal displaying and in-game displaying for some reasons (like zooming and easier management).The system has 3 cameras:
class CameraSystem { public var mainCam(default, null):FlxCamera; // displays menu and similar stuff public var playCam(default, null):PlayCamera; // has zooming behaviors public var hudCam(default, null):FlxCamera; // HUD elements overlaying playCam public function new() { mainCam = FlxG.camera; playCam = new PlayCamera(PlayCamera.FULL_SCREEN); hudCam = new FlxCamera(); }
It has some functions like:
// to switch between mainCam and playCam public function setDefaultToCam(cam:FlxCamera) { FlxG.cameras.remove(FlxG.cameras.list[0], false); FlxG.cameras.add(cam); FlxCamera.defaultCameras = [cam]; } // to set object's camera (mostly to hud) public inline function displayOnCam(object:FlxBasic, camera:FlxCamera) { object.cameras = [camera]; }
The camera system can be treated as an object and can be initialized by:
cameras = new CameraSystem();
The problem is: If the camera is initialized in PlayState, it would be okay but if it's initialized in MenuState, it will crash the game when switching state (from MenuState to PlayState)
I'm wondering if there's something which messes up the cameras at switching states.Error message
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData/copyPixels()
at flixel.graphics.frames::FlxFrame/paint()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\graphics\frames\FlxFrame.hx:296]
at flixel::FlxSprite/updateFramePixels()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\FlxSprite.hx:901]
at flixel::FlxSprite/calcFrame()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\FlxSprite.hx:877]
at flixel::FlxSprite/draw()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\FlxSprite.hx:620]
at flixel.group::FlxTypedGroup/draw()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\group\FlxGroup.hx:153]
at flixel.group::FlxTypedSpriteGroup/draw()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\group\FlxSpriteGroup.hx:210]
at flixel.group::FlxTypedGroup/draw()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\group\FlxGroup.hx:153]
at flixel.group::FlxTypedSpriteGroup/draw()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\group\FlxSpriteGroup.hx:210]
at flixel.group::FlxTypedGroup/draw()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\group\FlxGroup.hx:153]
at flixel.group::FlxTypedSpriteGroup/draw()[C:\HaxeToolkit\haxe\lib\flixel\4,1,0\flixel\group\FlxSpriteGroup.hx:210]
-
I'm wondering if there's something which messes up the cameras at switching states.
Cameras are reset and destroyed on state switches via
FlxG.cameras.reset()
.
-
Is there any reason to do this?
-
I'm also wondering if something also happens with the plugins at state switches since I create a HUD as a plugin and there's also a problem with drawing the HUD plugin after switching state.
-
So I decided to use just substates instead since this is a really complicated bug. It also somehow crashes the game when I set the camera zoom :/