Created
September 13, 2021 23:08
-
-
Save kinoko87/d004797af53b010f5c4232e25e934a51 to your computer and use it in GitHub Desktop.
A beat event system/Conductor in HaxeFlixel
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; | |
| import flixel.FlxG; | |
| using Math; | |
| using flixel.math.FlxMath; | |
| class Conductor | |
| { | |
| public static var bpm:Int = 100; | |
| public static var crochet:Float = ((60 / bpm)); | |
| public static var stepCrochet:Float = crochet / 4; | |
| public static var songPos:Float; | |
| public static var lastSongPos:Float; | |
| public static var offset:Float = 0; | |
| public static var secPerBeat:Float = (60 / bpm).round(); | |
| public static var curBeat:Int; | |
| public static var timeInSeconds:Float = 0; | |
| public static function changeBPM(newBpm:Int) | |
| { | |
| bpm = newBpm; | |
| crochet = (60 / bpm); | |
| stepCrochet = crochet / 4; | |
| secPerBeat = (60 / bpm).round(); | |
| } | |
| public static function update(elapsed:Float) | |
| { | |
| timeInSeconds = (Conductor.songPos / 1000); | |
| curBeat = Math.floor(timeInSeconds / (60 / Conductor.bpm)); | |
| songPos = FlxG.sound.music.time; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment