Created
November 25, 2021 16:58
-
-
Save shimeji87/371435e985bfafd6208c679e30b579cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import flixel.FlxCamera; | |
import flixel.FlxG; | |
import flixel.FlxSprite; | |
import flixel.util.FlxColor; | |
class CoolCamera | |
{ | |
public static var camera1:FlxCamera; | |
public static var camera2:FlxCamera; | |
public static function init(p1:FlxSprite, p2:FlxSprite) | |
{ | |
camera1 = createCamera(0, 0, FlxColor.WHITE, p1); | |
camera1.setSize(FlxG.width, FlxG.height); | |
camera2 = createCamera(0, 0, FlxColor.BLUE, p2); | |
FlxG.cameras.add(camera1); | |
FlxG.cameras.add(camera2); | |
} | |
public static function split(?follow1:FlxSprite, ?follow2:FlxSprite) | |
{ | |
// im lazy!! so i jsut make them into new cameras | |
FlxG.cameras.remove(camera1); | |
FlxG.cameras.remove(camera2); | |
camera1 = camera2 = null; | |
camera1 = createCamera(Std.int(FlxG.width / 2), 0, FlxColor.WHITE, follow1, false); | |
camera2 = createCamera(0, 0, FlxColor.BLUE, follow2, true); | |
FlxG.cameras.add(camera1); | |
FlxG.cameras.add(camera2); | |
} | |
public static function nest(?primaryCamera:FlxCamera, ?toBeNested:FlxCamera, ?xOffset:Float = 0, ?yOffset:Float = 0, ?resize:Bool = true) | |
{ | |
if (resize) | |
{ | |
if (primaryCamera.width == 0 && primaryCamera.height == 0) | |
{ | |
primaryCamera.setSize(Std.int(FlxG.width), Std.int(FlxG.height)); | |
} | |
toBeNested.setSize(Std.int(primaryCamera.width / 2), Std.int(primaryCamera.height / 2)); | |
} | |
toBeNested.setPosition((primaryCamera.x + primaryCamera.width / 4) + xOffset, (primaryCamera.y + primaryCamera.height / 4) + yOffset); | |
} | |
public static function createCamera(x:Int = 0, y:Int = 0, bgColor:Int = 0xFF000000, ?follow:FlxSprite, ?balls:Bool = false) | |
{ | |
var cam:FlxCamera = new FlxCamera(x, y, Std.int(FlxG.width / 2), FlxG.height); | |
cam.bgColor = bgColor; | |
if (follow != null) | |
cam.follow(follow); | |
return cam; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment