Created
February 5, 2021 03:23
-
-
Save MondayHopscotch/764d0980db0b0d7f66b17ba8cd4925aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 states; | |
| import flixel.util.FlxSpriteUtil; | |
| import shaders.Outline; | |
| import openfl.geom.Matrix; | |
| import openfl.geom.Point; | |
| import flixel.FlxCamera; | |
| import flixel.util.FlxColor; | |
| import flixel.FlxSprite; | |
| import flixel.FlxG; | |
| import flixel.FlxState; | |
| using extensions.FlxStateExt; | |
| class PlayState extends FlxState { | |
| public var one:FlxSprite; | |
| public var two:FlxSprite; | |
| public var three:FlxSprite; | |
| public var defaultCam:FlxCamera; | |
| public var outlineCam:FlxCamera; | |
| public var outlineSprite:FlxSprite; | |
| override public function create() { | |
| super.create(); | |
| defaultCam = new FlxCamera(0, 0, 400, 400); | |
| defaultCam.bgColor = FlxColor.BLACK; | |
| outlineCam = new FlxCamera(0, 400, 400, 400); | |
| outlineCam.bgColor = FlxColor.BLUE; | |
| outlineCam.x = 0; | |
| outlineCam.y = 400; | |
| FlxG.cameras.reset(defaultCam); | |
| FlxG.cameras.add(outlineCam); | |
| one = new FlxSprite(); | |
| one.makeGraphic(50, 50, FlxColor.BLUE); | |
| one.setPosition(50, 50); | |
| one.camera = outlineCam; | |
| add(one); | |
| two = new FlxSprite(); | |
| two.makeGraphic(50, 200, FlxColor.TRANSPARENT); | |
| FlxSpriteUtil.drawCircle(two, 25, 100, 10, FlxColor.BROWN); | |
| two.setPosition(100, 100); | |
| two.camera = outlineCam; | |
| add(two); | |
| three = new FlxSprite(); | |
| three.makeGraphic(75, 200, FlxColor.BROWN); | |
| three.setPosition(100, 100); | |
| three.camera = outlineCam; | |
| add(three); | |
| outlineSprite = new FlxSprite(); | |
| outlineSprite.makeGraphic(FlxG.width, FlxG.height, FlxColor.TRANSPARENT); | |
| // FlxSpriteUtil.drawCircle(outlineSprite, 100, 100, 30, FlxColor.BLUE); | |
| outlineSprite.shader = new Outline(FlxColor.RED, 0.1, 0.1); | |
| outlineSprite.camera = defaultCam; | |
| add(outlineSprite); | |
| } | |
| override public function update(elapsed:Float) { | |
| super.update(elapsed); | |
| one.x++; | |
| two.y++; | |
| three.setPosition(FlxG.mouse.x, FlxG.mouse.y); | |
| outlineSprite.drawFrame(); | |
| var screenPixels = outlineSprite.framePixels; | |
| if (FlxG.renderBlit) | |
| screenPixels.copyPixels(outlineCam.buffer, FlxG.camera.buffer.rect, new Point(), true); | |
| else | |
| screenPixels.draw(outlineCam.canvas, new Matrix(1, 0, 0, 1, 0, 0)); | |
| } | |
| override public function onFocusLost() { | |
| super.onFocusLost(); | |
| this.handleFocusLost(); | |
| } | |
| override public function onFocus() { | |
| super.onFocus(); | |
| this.handleFocus(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment