forked from Starmapo/FNF-PsychEngine-Extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuItem.hx
48 lines (39 loc) · 1.29 KB
/
MenuItem.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.math.FlxMath;
import flixel.util.FlxColor;
class MenuItem extends FlxSprite
{
public var targetY:Float = 0;
public var flashingInt:Int = 0;
public function new(x:Float, y:Float, weekName:String = '')
{
super(x, y);
var image = Paths.image('storymenu/$weekName');
if (image != null) loadGraphic(image);
antialiasing = ClientPrefs.globalAntialiasing;
}
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, CoolUtil.boundTo(elapsed * 10.2, 0, 1));
fakeFramerate = Math.round((1 / elapsed) / 10);
if (isFlashing)
flashingInt += 1;
if (isFlashing && flashingInt % fakeFramerate >= Math.floor(fakeFramerate / 2))
color = 0xFF33ffff;
else
color = FlxColor.WHITE;
}
}