2023-08-08 19:41:48 +00:00
|
|
|
package funkin.ui.title;
|
|
|
|
|
2023-08-08 20:37:17 +00:00
|
|
|
#if html5
|
|
|
|
import funkin.graphics.video.FlxVideo;
|
2024-01-13 02:52:28 +00:00
|
|
|
#end
|
|
|
|
#if hxCodec
|
2023-08-08 20:37:17 +00:00
|
|
|
import hxcodec.flixel.FlxVideoSprite;
|
|
|
|
#end
|
2023-11-07 09:04:22 +00:00
|
|
|
import funkin.ui.MusicBeatState;
|
2023-08-08 20:37:17 +00:00
|
|
|
|
2023-08-08 19:41:48 +00:00
|
|
|
/**
|
|
|
|
* After about 2 minutes of inactivity on the title screen,
|
|
|
|
* the game will enter the Attract state, as a reference to physical arcade machines.
|
|
|
|
*
|
2024-04-29 21:51:36 +00:00
|
|
|
* In the current version, this just plays the ~~Kickstarter trailer~~ Erect teaser, but this can be changed to
|
2023-08-08 19:41:48 +00:00
|
|
|
* gameplay footage, a generic game trailer, or something more elaborate.
|
|
|
|
*/
|
|
|
|
class AttractState extends MusicBeatState
|
|
|
|
{
|
2024-04-30 23:01:39 +00:00
|
|
|
static final ATTRACT_VIDEO_PATH:String = Paths.stripLibrary(Paths.videos('toyCommercial'));
|
2023-08-08 20:37:17 +00:00
|
|
|
|
|
|
|
public override function create():Void
|
|
|
|
{
|
|
|
|
// Pause existing music.
|
2024-03-23 21:50:48 +00:00
|
|
|
if (FlxG.sound.music != null)
|
|
|
|
{
|
|
|
|
FlxG.sound.music.destroy();
|
|
|
|
FlxG.sound.music = null;
|
|
|
|
}
|
2023-08-08 20:37:17 +00:00
|
|
|
|
|
|
|
#if html5
|
2024-03-28 04:01:42 +00:00
|
|
|
trace('Playing web video ${ATTRACT_VIDEO_PATH}');
|
2023-08-08 20:37:17 +00:00
|
|
|
playVideoHTML5(ATTRACT_VIDEO_PATH);
|
2024-01-13 02:52:28 +00:00
|
|
|
#end
|
|
|
|
|
|
|
|
#if hxCodec
|
2024-03-28 04:01:42 +00:00
|
|
|
trace('Playing native video ${ATTRACT_VIDEO_PATH}');
|
2023-08-08 20:37:17 +00:00
|
|
|
playVideoNative(ATTRACT_VIDEO_PATH);
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
|
|
|
#if html5
|
|
|
|
var vid:FlxVideo;
|
|
|
|
|
|
|
|
function playVideoHTML5(filePath:String):Void
|
|
|
|
{
|
|
|
|
// Video displays OVER the FlxState.
|
|
|
|
vid = new FlxVideo(filePath);
|
|
|
|
if (vid != null)
|
|
|
|
{
|
|
|
|
vid.zIndex = 0;
|
|
|
|
|
|
|
|
vid.finishCallback = onAttractEnd;
|
|
|
|
|
|
|
|
add(vid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace('ALERT: Video is null! Could not play cutscene!');
|
|
|
|
}
|
|
|
|
}
|
2024-01-13 02:52:28 +00:00
|
|
|
#end
|
|
|
|
|
|
|
|
#if hxCodec
|
2023-08-08 20:37:17 +00:00
|
|
|
var vid:FlxVideoSprite;
|
|
|
|
|
|
|
|
function playVideoNative(filePath:String):Void
|
|
|
|
{
|
|
|
|
// Video displays OVER the FlxState.
|
|
|
|
vid = new FlxVideoSprite(0, 0);
|
|
|
|
|
|
|
|
if (vid != null)
|
|
|
|
{
|
|
|
|
vid.zIndex = 0;
|
|
|
|
vid.bitmap.onEndReached.add(onAttractEnd);
|
|
|
|
|
|
|
|
add(vid);
|
|
|
|
vid.play(filePath, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace('ALERT: Video is null! Could not play cutscene!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#end
|
2023-08-08 19:41:48 +00:00
|
|
|
|
2023-08-08 20:37:17 +00:00
|
|
|
public override function update(elapsed:Float):Void
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
|
|
|
// If the user presses any button, skip the video.
|
|
|
|
if (FlxG.keys.justPressed.ANY)
|
|
|
|
{
|
|
|
|
onAttractEnd();
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 19:41:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When the attraction state ends (after the video ends or the user presses any button),
|
|
|
|
* switch immediately to the title screen.
|
|
|
|
*/
|
|
|
|
function onAttractEnd():Void
|
|
|
|
{
|
2023-08-08 20:37:17 +00:00
|
|
|
#if html5
|
|
|
|
if (vid != null)
|
|
|
|
{
|
|
|
|
remove(vid);
|
|
|
|
}
|
2024-01-13 02:52:28 +00:00
|
|
|
#end
|
|
|
|
|
|
|
|
#if hxCodec
|
2023-08-08 20:37:17 +00:00
|
|
|
if (vid != null)
|
|
|
|
{
|
|
|
|
vid.stop();
|
|
|
|
remove(vid);
|
|
|
|
}
|
|
|
|
#end
|
2024-01-13 02:52:28 +00:00
|
|
|
|
|
|
|
#if (html5 || hxCodec)
|
2023-08-08 20:37:17 +00:00
|
|
|
vid.destroy();
|
|
|
|
vid = null;
|
2024-01-13 02:52:28 +00:00
|
|
|
#end
|
2023-08-08 20:37:17 +00:00
|
|
|
|
2024-02-06 00:46:11 +00:00
|
|
|
FlxG.switchState(() -> new TitleState());
|
2023-08-08 19:41:48 +00:00
|
|
|
}
|
|
|
|
}
|