How do you expand FlxCamera?



  • So I was just playing around with the camera and came up with this:

       public static function setZoom(newZoom:Float) {
    		FlxG.camera.zoom = newZoom;
    		FlxG.camera.setSize(cast FlxG.width / newZoom, cast FlxG.height / newZoom);
    		FlxG.camera.setCenter(DPosUtil.screenCenter); // center camera
    	}
    

    Don't know if this is the way to do it?

    Also: How to center a tilemap?
    Here's Pong resized using the function above (zoom = 0.5)
    The camera is following the ball and the scroll bound rect is set to the tilemap.
    alt text



  • How about following the tilemap instead of ball?



  • Didn't think of that but it doesn't solve the problem though.



  • What are you trying yo do exactly?

    Maybe it has something to do with scale modes.



  • Nevermind, I solved it by resize the scroll bound to the size of the camera and center it around the tilemap like this:

        public static function setZoom(newZoom:Float, tilemap:FlxTilemap) {
            var camera = FlxG.camera;
    		
            camera.zoom = newZoom;
            camera.setSize(cast FlxG.width / newZoom, cast FlxG.height / newZoom);
            camera.setCenter(DPosUtil.screenCenter);
    
            var scrollBound = FlxRect.get(0, 0, camera.width, camera.height);
            scrollBound.setCenter(tilemap.getCenter());
            camera.setScrollBoundsRect(scrollBound.x, scrollBound.y, scrollBound.width, scrollBound.height);
    	}
    

Log in to reply