Multimedia

Project DVN

The following document describes multimedia usage in DVN.

Contents


Hot Reloading of Resources

DVN allows hot reloading of resources when you're within a scene.

Simply reload the scene using F5.

This will reload all resources, including scripts and characters.

Images

In general images are loaded the same way as characters, backgrounds etc. but they have their own file located in:

data/resources/main.json

The format is the exact same as characters.json and backgrounds.json

{
  "ImageName": {
    "path": "path/to/image.png"
  },
  ...
}

Now you can easily construct images using the given image name.

Example:

auto image = new Image(window, "ImageName");

Note: Since characters and backgrounds are images also technically you can set images as backgrounds and characters too, but it's generally not recommended.

Animations

Animations use sprite sheets for their animation with a single row supported only.

The format is similar to images, but you need to be more explicit.

Animations are added to the file:

data/game/animations.json

If the file doesn't exist then you must create it.

Data format example:

{
    "AnimationName": {
        "path": "data/game/animations/myanimation.png",
        "size": {
            "width": 128,
            "height": 128
        },
        "columns": 4
    },
    ...
}
  • AnimationName is the name of the animation.
  • path is the path to the animation sprite sheet.
  • size is the size of a single column.
  • columns is the amount of columns.

Now you can create animations:

auto ani = new Animation(window, "AnimationName");

Audio (music, SFX, voice)

Music and sound effects are defined in:

data/game/music.json

The data format is simply a map of keys to paths of music/sound effects.

{
    "MusicName": "path/to/music.mp3",
    "SFXName": "path/to/sfx.wav",
    "VoiceName": "path/to/voice.wav"
}

There's no high-level API for audio in DVN, but luckily the functions are straight forward.

string getMusicPath(string music); // The music parameter is the music name -- The function returns the path of the music
void EXT_SetSoundVolume(int volume);
void EXT_ValidateMusic();
void EXT_PlayLastMusic();
void EXT_PlayMusic(string path);
void EXT_PauseMusic();
void EXT_StopMusic();
int EXT_PlaySound(string path);
void EXT_StopSound();

Video

Video files are not directly supported, BUT DVN does support framed videos in that every frame from a video can be extracted and played back.

Basically extract all frames from a video using something like https://www.ffmpeg.org/ then place them in a folder ex. “data/game/videos/myvideo” where each file is named something like "1.png" "2.png" etc. in the order you want them played.

The following cmd can be used with ffmpeg to extract all frames of a video named "video.mp4" into a folder named "frames".

ffmpeg -i "video.mp4" "frames/%%d.png"

When that is finished you can create a video component in your view and display the video like below:

auto video = new Video(window, "data/game/videos/myvideo");
addComponent(video);
video.size = IntVector(1280, 720);

You can use the event onFinishedVideo to handle when a video has finished playing. This is useful if you have an intro view before the main menu view and want the main menu displayed after the video finishes.

Note: Intro videos are now officially supported by Project DVN and doesn’t require a custom view.

Example:

video.onFinishedVideo({
    displayView("MainMenu");
});

Preloading

All multimedia assets except audio is preloaded in DVN, this means application load time can be slower (but generally still very fast.) - however application runtime is super fast.

The gallery in DVN allows for any image to be represented. Just drop the images into the data/game/gallery folder and it will be displayed. You can drop the images in dynamically, meaning it can be used for unlockables.

Generally it is used for screenshots taken by the user, but it can be any sort of PNG image.