Friday Night Funkin' Cookbook
Friday Night Funkin' CookbookAdvancedVideo Cutscenes

Video Cutscenes

Reading time: 1.5 minute

This chapter will specifically walk through using scripted Songs to implement a Video Cutscene into a mod.

import funkin.play.PlayState;
import funkin.play.song.Song;
import funkin.play.cutscene.VideoCutscene;

class DetectedSong extends Song
{
    var hasPlayedCutscene:Bool;
    var bgSprite:FunkinSprite;

    public function new()
    {
        super('detected');

        hasPlayedCutscene = false;
    }

    public override function onCountdownStart(event:CountdownScriptEvent):Void
    {
        super.onCountdownStart(event);

        hasPlayedCutscene = !PlayStatePlaylist.isStoryMode;

        if (!hasPlayedCutscene)
            return;

        // We are playing the video cutscene
        hasPlayedCutscene = true;

        // Cancel the countdown.
        event.cancel();

        // Hide the UI with a black rectangle sprite.
        bgSprite = new FunkinSprite(0, 0);
        bgSprite.makeSolidColor(2000, 2500, 0xFF000000);
        bgSprite.cameras = [PlayState.instance.camCutscene];
        bgSprite.zIndex = -10000;

        // Add to playstate
        PlayState.instance.add(bgSprite);
        PlayState.instance.refresh();

        // Play the video (defaults to assets/videos/videos/detected.mp4)
        VideoCutscene.play(Paths.videos("detected"));
    }
}

How it works

We create a few variables at the top to dictate the state of the cutscene, and a black rectangle we use to hide the ui. We then override the countdown start event of the song, because that is the perfect time for us to start a video.

It's after everything is loaded, and the game hasn't actually shown anything (usually) yet.

We check if we're not in story mode, if we aren't (like freeplay), we can safely skip the cutscene.

If we are in story mode, we cancel the event, create the black rectangle, and start the cutscene with VideoCutscene.Play(string); with Paths.videos(string) dictating our path.

Paths.videos prepends assets/videos/videos/ to the path, so make sure your videos are in that path in your mod (ex: mods/Hex-VSlice/videos/videos/detected.mp4)


Contributors:
Cameron Taylor
kade-github
Last modified:
Created:
Category:  Advanced