Created
July 16, 2022 18:56
-
-
Save EliteMasterEric/58755a4ae5ef8a8fe4e898371c93b8b1 to your computer and use it in GitHub Desktop.
A script that defines the behavior for a custom scripted FlxState.
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
| import flixel.FlxSprite; | |
| import flixel.FlxG; | |
| import funkin.Paths; | |
| import funkin.MainMenuState; | |
| import funkin.MusicBeatState; | |
| import flixel.tweens.FlxTween; | |
| import flixel.system.FlxSound; | |
| class CustomState extends MusicBeatState | |
| { | |
| public function new() | |
| { | |
| super(); | |
| } | |
| var backgroundMusic:FlxSound; | |
| var catSprite:FlxSprite; | |
| override function create() { | |
| super.create(); | |
| FlxG.sound.music.pause(); | |
| catSprite = new FlxSprite(0, 0); | |
| catSprite.frames = Paths.getSparrowAtlas("catvibe/crumb"); | |
| // Place the cat sprite in the center of the screen | |
| catSprite.x = FlxG.width / 2 - catSprite.width / 2; | |
| catSprite.y = FlxG.height / 2 - catSprite.height / 2; | |
| catSprite.alpha = 0; | |
| catSprite.animation.addByPrefix('idle', 'idle 0', 12, true); | |
| catSprite.animation.play('idle'); | |
| // Add the cat sprite to the state | |
| add(catSprite); | |
| // Fade the cat sprite in over 2.5 seconds | |
| FlxTween.tween(catSprite, {alpha: 1}, 4, {ease: FlxTween.linear}); | |
| // Play the music | |
| backgroundMusic = new FlxSound().loadEmbedded(Paths.music('catvibe/darkagedrop'), true, true); | |
| backgroundMusic.volume = 0; | |
| backgroundMusic.play(); | |
| } | |
| override function update(elapsed:Float) { | |
| super.update(elapsed); | |
| if (backgroundMusic != null && backgroundMusic.volume < 1.0) | |
| backgroundMusic.volume += 1.0 / 2.5 * elapsed; | |
| if (controls.BACK) | |
| { | |
| FlxG.sound.play(Paths.sound('cancelMenu')); | |
| backgroundMusic.stop(); | |
| backgroundMusic = null; | |
| FlxG.switchState(new MainMenuState()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment