From eeda572c3ee5aec14da4aedbe227d41475c80475 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 1 Mar 2021 22:35:27 -0500 Subject: [PATCH] easier storymode menu adding onto --- source/MenuItem.hx | 42 ++++++++++++++++++++++++---------------- source/StoryMenuState.hx | 2 +- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/source/MenuItem.hx b/source/MenuItem.hx index fe3c9f238..f41d893c7 100644 --- a/source/MenuItem.hx +++ b/source/MenuItem.hx @@ -1,41 +1,49 @@ package; +import flixel.FlxG; import flixel.FlxSprite; import flixel.graphics.frames.FlxAtlasFrames; import flixel.group.FlxSpriteGroup; import flixel.math.FlxMath; +import flixel.util.FlxColor; class MenuItem extends FlxSpriteGroup { public var targetY:Float = 0; public var week:FlxSprite; + public var flashingInt:Int = 0; public function new(x:Float, y:Float, weekNum:Int = 0) { super(x, y); - - var tex = Paths.getSparrowAtlas('campaign_menu_UI_assets'); - - week = new FlxSprite(); - week.frames = tex; - // TUTORIAL IS WEEK 0 - week.animation.addByPrefix('week0', 'tutorial selected', 24); - week.animation.addByPrefix('week1', "WEEK1 select", 24); - week.animation.addByPrefix('week2', "week2 select", 24); - week.animation.addByPrefix('week3', "Week 3 press", 24); - week.animation.addByPrefix('week4', "Week 4 press", 24); - week.animation.addByPrefix('week5', "week 5", 24); - week.animation.addByPrefix('week6', "Week 6", 24); + week = new FlxSprite().loadGraphic(Paths.image('storymenu/week' + weekNum)); add(week); - - week.animation.play('week' + weekNum); - week.animation.pause(); - week.updateHitbox(); } + private var isFlashing:Bool = false; + + public function startFlashing():Void + { + isFlashing = true; + } + + // if it runs at 60fps, fake framerate will be 6 + // if it runs at 144 fps, fake framerate will be like 14, and will update the graphic every 0.016666 * 3 seconds still??? + // so it runs basically every so many seconds, not dependant on framerate?? + // I'm still learning how math works thanks whoever is reading this lol + var fakeFramerate:Int = Math.round((1 / FlxG.elapsed) / 10); + override function update(elapsed:Float) { super.update(elapsed); y = FlxMath.lerp(y, (targetY * 120) + 480, 0.17); + + if (isFlashing) + flashingInt += 1; + + if (flashingInt % fakeFramerate >= Math.floor(fakeFramerate / 2)) + week.color = 0xFF33ffff; + else + week.color = FlxColor.WHITE; } } diff --git a/source/StoryMenuState.hx b/source/StoryMenuState.hx index 1156ccade..1e27eed7c 100644 --- a/source/StoryMenuState.hx +++ b/source/StoryMenuState.hx @@ -291,7 +291,7 @@ class StoryMenuState extends MusicBeatState { FlxG.sound.play(Paths.sound('confirmMenu')); - grpWeekText.members[curWeek].week.animation.resume(); + grpWeekText.members[curWeek].startFlashing(); grpWeekCharacters.members[1].animation.play('bfConfirm'); stopspamming = true; }