GUI elements on top of video?

Started by Darjanator, Sun 30/06/2019 01:43:49

Previous topic - Next topic

Darjanator

Hi, yesterday I was inspired to make a game along the lines of Mission Critical, one of my favourite games from my childhood.

Fast forward 24 hours I've downloaded AGS and have gotten quite familiar with the program and the scripting, but now I've caught a bit of a snag.

The way I've envisioned the game to run (and TBH having it be a complete rip off of Mission Critical) is for it to be a first person view game with full 360° freedom of view (4x90° increments) in strategic spots, connected by an animation played via playvideo. I can't seem to push the video under my GUI elements, though as was the case in the original game. Am I missing something or is this somewhat an impossibility atm?

I'm playing the videos as so:

Code: ags

function room_Load()
{
  if (player.PreviousRoom == 2)
  {
    PlayVideo("video/transitions/transition room 2 to 1.ogv", eVideoSkipAnyKeyOrMouse,  0); // plays transition animation
  }
  SetViewport(orientation, 0); // snaps orientation global
  aRny_ambient.Play(eAudioPriorityNormal, eRepeat); // plays ambient sound on loop
}


Would I need to play the video in another way that would allow me to put GUI elements on top of it? Is such a thing even possible?

Vincent


Darjanator

#2
Quote from: Vincent on Sun 30/06/2019 07:37:00
You can put GUI elements above the video by using this plugin:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=34910.0
Oh, fantastic. Got it to work, except now I have to figure out how to close it after it's done playing. The thread says I have to "set pointer to null". If only I knew what that actually meant, haha...

I'm not good at programming... :(

EDIT: Wait...

Code: ags
      if(video.ended == 1)
      {
        video = null;
      }


Was it really that easy?

Vincent

Yes to set a pointer to null you can do it in that way. Anyway I can't help but notice that you're using a boolean to keep track of which video you're running?

Code: ags
if(video.ended == 1)


The author of the plugin shared the details of the features he used in it:

Code: ags
readonly bool ended;    // end of video was hit, no more new frames will appear unless looped


This will not going to work the way you mean I suppose. If you want to keep track of when a specific video ends you have to do it another way.
For example like this:

Code: ags

int VideoID;
Theora* video;


enum Videoclip
{
  Intro = 0, 
  FirstScene = 1, 
  SecondScene = 2
};


function room_Load()
{
  VideoID = Intro;
}


function check_videoID_running()
{
  if (video.ended)
  {
    if (VideoID == Intro)
    {
      video = Theora.Open("Video/FirstScene.ogg");
      VideoID = FirstScene;
    }
  
  
    else if (VideoID == FirstScene)
    {
      video = Theora.Open("Video/SecondScene.ogg");
      VideoID = SecondScene;
    }
  }
}


function repeatedly_execute() 
{
  check_videoID_running();
}

Darjanator

I don't know if that's going to mean much. The only reason for the videos is the transitions between rooms and they play on room_Load() depending on which was the previousroom. I don't plan on expanding the video functionality any more. If I were to use this as a base for a more complex game, I'll look into it definitely, but as it is, a single video per room playing is all I need.

Crimson Wizard

Quote from: Darjanator on Sun 30/06/2019 17:16:42
I don't know if that's going to mean much. The only reason for the videos is the transitions between rooms and they play on room_Load() depending on which was the previousroom. I don't plan on expanding the video functionality any more. If I were to use this as a base for a more complex game, I'll look into it definitely, but as it is, a single video per room playing is all I need.

I have to note, I dont recommend doing anything visual-related in room_Load, because that event is happening before room is first shown on screen. The proper way to do any cutscenes/custom transitions is "After fade in" event. (Probably also setting default transition style to "Instant" so that it does not interfere with your videos)

Darjanator

Quote from: Crimson Wizard on Sun 30/06/2019 17:29:01
Quote from: Darjanator on Sun 30/06/2019 17:16:42
I don't know if that's going to mean much. The only reason for the videos is the transitions between rooms and they play on room_Load() depending on which was the previousroom. I don't plan on expanding the video functionality any more. If I were to use this as a base for a more complex game, I'll look into it definitely, but as it is, a single video per room playing is all I need.

I have to note, I dont recommend doing anything visual-related in room_Load, because that event is happening before room is first shown on screen. The proper way to do any cutscenes/custom transitions is "After fade in" event. (Probably also setting default transition style to "Instant" so that it does not interfere with your videos)
Noted! Will change it up.

Darjanator

Quote from: Crimson Wizard on Sun 30/06/2019 17:29:01
Quote from: Darjanator on Sun 30/06/2019 17:16:42
I don't know if that's going to mean much. The only reason for the videos is the transitions between rooms and they play on room_Load() depending on which was the previousroom. I don't plan on expanding the video functionality any more. If I were to use this as a base for a more complex game, I'll look into it definitely, but as it is, a single video per room playing is all I need.

I have to note, I dont recommend doing anything visual-related in room_Load, because that event is happening before room is first shown on screen. The proper way to do any cutscenes/custom transitions is "After fade in" event. (Probably also setting default transition style to "Instant" so that it does not interfere with your videos)
I changed it, but then the video doesn't play at the correct time. It first shows the new room for a single frame and only then plays the video. On room_Load() it plays it properly and there's no stutter.

Crimson Wizard

Quote from: Darjanator on Mon 01/07/2019 03:32:42
I changed it, but then the video doesn't play at the correct time. It first shows the new room for a single frame and only then plays the video. On room_Load() it plays it properly and there's no stutter.

I see, maybe plugin overrides the engine's drawing logic.

Cassiebsg

You could take the first frame of the video and use it as the starting BG image for that room (either by setting a 2nd BG, as an object, GUI, dynamic sprite...) and then you can set the normal BG back once the video has started playing.
There are those who believe that life here began out there...

Crimson Wizard

Quote from: Cassiebsg on Mon 01/07/2019 11:41:31
You could take the first frame of the video and use it as the starting BG image for that room (either by setting a 2nd BG, as an object, GUI, dynamic sprite...) and then you can set the normal BG back once the video has started playing.

Hm, if you go into this direction, you could clear the room background with black color in room_Load and restore it after the video.

Darjanator

Quote from: Cassiebsg on Mon 01/07/2019 11:41:31
You could take the first frame of the video and use it as the starting BG image for that room (either by setting a 2nd BG, as an object, GUI, dynamic sprite...) and then you can set the normal BG back once the video has started playing.

Is it really that much of an issue? What sort of problems could arise?

Crimson Wizard

#12
Quote from: Darjanator on Mon 01/07/2019 21:15:41
Quote from: Cassiebsg on Mon 01/07/2019 11:41:31
You could take the first frame of the video and use it as the starting BG image for that room (either by setting a 2nd BG, as an object, GUI, dynamic sprite...) and then you can set the normal BG back once the video has started playing.

Is it really that much of an issue? What sort of problems could arise?

This is a guess (because I haven't tried this video plugin), but it may not work in future versions of AGS, where engine has additional optimisations and skips all drawing, including plugins, while the game is in "fade out" state.

However, the fact that video is not drawn during first visible frame in the room indicates there's a problem somewhere, in script, plugin or engine. I believe it's worth investigating at some point.

Darjanator

#13
Another issue arises. I'm trying to use this plugin for playing animations I captured as .ogv files as a state change of an item in the scene. That's reflected as an object, whose visibility is enabled.

I'm trying to trigger that to coincide with the video playback ending, but other than putting it into repeatedly_execute, where I don't know how to specify which video exactly is playing (there will be several per room), I have no idea how.

Also, I think there's an issue with the module. My compiled .exe is getting really big (65MB for the .exe, I've gone through all the images and sounds and they total 12.6MB). I think the module, even though it requires external files, is compiling the .ogv into the .exe and then not removing them when they're no longer called.

Cassiebsg

Well, if you have a video per room, you can always check what room the player is in as well as video finished. Otherwise you can create a variable for each different video when you start it, and then check that once it's finished.

As far as I know, the module should not import video into the game exe, it just reads and plays the external file. Try setting the compression for images in settings and see if that helps.
There are those who believe that life here began out there...

Crimson Wizard

#15
Quote from: Darjanator on Tue 09/07/2019 03:19:31I think the module, even though it requires external files, is compiling the .ogv into the .exe and then not removing them when they're no longer called.

AGS automatically adds all OGV video files into exe if it finds them in the root project directory. This is done in case you play them using standard PlayVideo function, but it does not detect if you really do.

I may suggest maybe try to store video files inside a subfolder and then manually copy to Compiled/Windows.

Darjanator

Quote from: Crimson Wizard on Tue 09/07/2019 12:08:06
Quote from: Darjanator on Tue 09/07/2019 03:19:31I think the module, even though it requires external files, is compiling the .ogv into the .exe and then not removing them when they're no longer called.

AGS automatically adds all OGV video files into exe if it finds them in the root project directory. This is done in case you play them using standard PlayVideo function, but it does not detect if you really do.

I may suggest maybe try to store video files inside a subfolder and then manually copy to Compiled/Windows.
That's what I've been doing. Guess the file size is just that large.

Darjanator

#17
Quote from: Cassiebsg on Tue 09/07/2019 12:01:28
Otherwise you can create a variable for each different video when you start it, and then check that once it's finished.

This is what I have so far:

Code: ags
Theora* video;

bool TestVideoEnded;

function repeatedly_execute() 
{
  if(video)
  {
    mouse.Visible = false;
    video.DrawEx(DsBackground, 160.0, 120.0, 0.25, 0.25, 0.0, RtScreen);
    video.NextFrame();
    if(video.ended == true)
    {
      video = null;
      mouse.Visible = true;
    }
  }
  if (TestVideoEnded == true)
  {
    object[2].Visible = true;
  }
}

function TestVideo()
{
  video = Theora.Open("video/test.ogv");
  video.loop = false;
  if (video.ended == true)
  {
    TestVideoEnded = true;
  }
}


After the video is done playing, it closes, but the object doesn't show up.

It seems to me that if (video.ended == true) has to be the repeatedly_execute(), but how do I specify which video is playing there?

Crimson Wizard

Is this a global script? If you were running/testing video in a room script you wouldn't have to do object[2] but could use actual object's script name instead.

Quote
It seems to me that if (video.ended == true) has to be the repeatedly_execute(), but how do I specify which video is playing there?

Guess this depends on whether video playback is blocking or non-blocking. If it's non-blocking, then ofcourse you will have to test in rep_exec.

I don't know which video ID would you require, but as a random idea, you may save video filename in a String variable and check that to know which video was played last.

Darjanator

Quote from: Crimson Wizard on Tue 09/07/2019 14:04:39
Is this a global script? If you were running/testing video in a room script you wouldn't have to do object[2] but could use actual object's script name instead.

Quote
It seems to me that if (video.ended == true) has to be the repeatedly_execute(), but how do I specify which video is playing there?

Guess this depends on whether video playback is blocking or non-blocking. If it's non-blocking, then ofcourse you will have to test in rep_exec.


Using video with this plugin, it is non-blocking. I wouldn't have this issue if PlayVideo had a zorder property so I could put it below my inventory GUI. :D

QuoteI don't know which video ID would you require, but as a random idea, you may save video filename in a String variable and check that to know which video was played last.

It is a global thing, because I'm calling the function from a dialog and I haven't been able to figure out how to call a function from a room or inject the theora plugin straight into the dialog.

SMF spam blocked by CleanTalk