Open SomeGuyWhoLovesCoding opened 6 months ago
This is playstate:
package;
import flixel.*;
class PlayState extends FlxState
{
public var channel:SoundChannel;
override public function create()
{
FlxG.stage.window.frameRate = 57.59999999999998;
super.create();
channel = new SoundChannel();
}
override public function update(elapsed:Float)
{
if (FlxG.keys.justPressed.ENTER)
{
channel.play("music", "assets/ogg.ogg");
}
if (FlxG.keys.justPressed.SPACE)
{
channel.setPause("music", !channel.getPause("music"));
}
if (FlxG.keys.justPressed.ESCAPE)
{
channel.stop("music");
}
trace(formatTime(channel.getTimeOf("music"), true, true), formatTime(channel.getLengthOf("music"), true, true));
super.update(elapsed);
}
/**
* Format seconds as minutes with a colon, an optionally with milliseconds too.
*
* @param ms The number of seconds (for example, time remaining, time spent, etc).
* @param EnglishStyle Whether to show a ":" instead of a ";".
* @param showMS Whether to show a "." after seconds aswell.
* @return A nicely formatted String, like "1:03.45".
*/
inline public function formatTime(ms:Float, englishStyle:Bool, showMS:Bool):String
{
// Rewritten code??? Moment when I use ChatGPT:
var milliseconds:Int = Std.int(ms * 0.1) % 100;
var seconds:Int = Std.int(ms * 0.001);
var hours:Int = Std.int(seconds / 3600);
seconds %= 3600;
var minutes:Int = Std.int(seconds / 60);
seconds %= 60;
var t:String = ';';
if (englishStyle)
t = ':';
var c:String = ',';
if (englishStyle)
c = '.';
var time:String = '';
if (!Math.isNaN(ms)) {
if (hours > 0) time += '$hours$t';
time += '${minutes < 10 && hours > 0 ? '0' : ''}$minutes$t';
if (seconds < 10) time += '0';
time += seconds;
} else
time = 'NaN';
if (showMS) {
if (milliseconds < 10)
time += '${c}0$milliseconds';
else
time += '${c}$milliseconds';
}
return time;
}
}
Code:
Error: