Playing a Video In-Game?

Started by Sickened, Tue 28/06/2011 07:02:49

Previous topic - Next topic

Sickened

Alright, so maybe this is a really simply thing, but for some reason, I can't seem to find the answer. All I want to do is to play "cutscenes" in-game, but in a video format, such as wmv, avi, whatever, for a more "modern" feel I guess? I already have the videos made, and they're currently in wmv format, but I can easily change that if necessary. So basically, how can I get one of these videos to, say, start playing when you enter a room, or click on an object/character, and is this possible?

suicidal pencil

#1
AGS has built-in support for OGG Theora (.OGV) video files, and can play anything that Windows Media Player can play (just so long as the end-user has the correct codec installed).

the code is pretty simple, and if you want it to play when the player enters the room:
Code: ags

function room_AfterFadeIn()
{
  PlayVideo("VideoName.OGV", eVideoSkipNotAllowed, 1);
}


Just keep in mind that the game is paused while the video runs.

and all this information was found in the AGS help ;) Remember: F1 helps  ;D

edit: (.OGV, not .OVG)

monkey0506

Something to keep in mind about playing a video file is that if it's a format such as WMV, AVI, MPG, etc. the user has to have the appropriate codec installed, and you have to release the video file directly, it cannot be compiled into your game.

If you convert your video files to OGG Theora then your game isn't dependent on the player having the correct codec, and the video can be compiled into your game EXE. There are a lot of free converters out there, just Google them. I'd actually recommend SUPER which is completely free and doesn't add any watermarks or anything to your videos, and is compatible with basically every video format there is.

If you do convert your videos to Theora, they may have an .OGG extension, but you can change that to .OGV (not OVG ;)) directly, the format is the same.

suicidal pencil

 Good catch, monkey :P it's been a long night, and it's promising to get longer (just so long as I can stay awake until that 2nd pot of coffee is done. Code doesn't write itself (usually...))

I don't know too much about the pros/cons in the different video files, but seeing as OGG is unrestricted by any software patents, and can use the lossless audio compression codec FLAC, I heavily recommend it  ;D


arj0n

Like said before, the biggest pro of using OGG/OGV, is the that the user doesn't need to have the appropriate codec installed  :)

Software (freeware):
Converter: ffmpeg2theora-0.27
Frontend: GFrontend (ffmpeg2theora) v2007.2 Final

And a small tip because this goes wrong often:
Don't use the playvideo code in 'Before Fade In' a.k.a. "function room_Load()",
use 'After Fade In' a.k.a. "function room_AfterFadeIn()".  ;)

Toonloon

How do you get your video to play before a room loads? At the moment I've got the command at  the FirstLoad function, and I'm seeing a second or two of my room before the video loads. I'd rather just see the video first, then see the room.

arj0n

#6
Play it in another room first (which is only used for the video to play). Once done load the room you are talking about?

Toonloon

I was using the tutorials last night to try and create an animated room, using the Sammy's Quest videos, and I had problems with some of the functions. I kept getting undefined token errors. I did manage to get it to work somehow, but when I saw this post this morning, I thought this would be a much better way.

Sadly, I haven't been able to get the function correct to load the next room immediately after the video. Do you know what it is? Also, (last question) do you have your player start in that room even if it's just a video and it moves on to the next? I thought not, but then it wouldn't load first when I tried it.

I'm a complete noob, if you hadn't guessed.

Ghost

AGS always has the player int he room that's currently displayed, or, other way round, always shows the room you just moved the player to.

But since you can use pretty much every non-blocking command before a room's loaded, just:

function room_Load()
{
    player.y = 1000;
}

Alternatively, rooms allow you to make the player invisible in their properties panel.

arj0n

Quote from: Toonloon on Tue 28/06/2011 11:02:40
Sadly, I haven't been able to get the function correct to load the next room immediately after the video. Do you know what it is?
Character.ChangeRoom(int room_number, optional int x, optional int y)

Quote from: Toonloon on Tue 28/06/2011 11:02:40
Also, (last question) do you have your player start in that room even if it's just a video and it moves on to the next? I thought not, but then it wouldn't load first when I tried it.
Yes, the player will be in that room. (There are ways to make him/her not visible if needed but that might not be necessary if you jump to another room right after the video. )

Khris

Quote from: Toonloon on Tue 28/06/2011 11:02:40I kept getting undefined token errors.

There are two possible reason for this I can see:
Either you're misspelling commands. Capitalization is important; AGS is case-sensitive. But there's the auto-complete window so I'd be surprised if that's actually the problem.
Or, more likely, you're adding commands outside of functions. Both the tutorial and Densming's videos keep showing how to add event functions and only to put code inside them, so again I'd be surprised if that's the problem.

Could you elaborate a bit, post the code you're trying to use and tell us why showing a video is supposed to solve your problem?

(We're hijacking this thread btw, but I guess the OP's question is answered.)

Toonloon

I get  an error stating "must have an instance of the struct to acess an non static member".

Tried with or without the option x and y variables. Still no joy.

Here's my script:

// room script file

function room_AfterFadeIn()
{
 PlayVideo("title1.avi", eVideoSkipNotAllowed, 1);
 Character.ChangeRoom(int 1)
}


On an unrelate note, I've seen a couple of comments from people who have been kind enough to help me, say that I should use the tutorials. I am using the tutorials but somethings dont' add up to me. For example, the PlaySound command featured in densming's videos, just doesn't work for me. I went through his cutscene tutorials line by line and yet something wasn't working out at my end. Has there been any changes to the functions in recent versions?

NickyNyce

@Toonloon , I had a bit of trouble myself with the sounds, rename them Sound1, Sound2, so on and so forth in your sound folder. That did the trick for me

arj0n


Toonloon


Khris

A struct is a sort of template, the outline of a data structure (also called "class" in other programming languages).

The programmer subsequently creates so called instances that use the structure; think of the struct as a blank form, and an instance is a filled out copy of the original form.

In AGS, every character you create in the editor is actually an instance of the Character struct.
So if you create a character named cEgo, you can now access its data using e.g. cEgo.x or cEgo.Name.

"player" is a pointer pointing to the current player character. So if you want to do anything to the player character, that's what you have to use in the actual command instead of "Character" (otherwise how is AGS supposed to know which character you're "talking about"?)

So the solution would be to use:

Code: ags
  player.ChangeRoom(1);


No need for the "int" part; this just tells you the type of parameter you're supposed to use.

(sort of explained in part 7 of the AGS tutorial)


As for the sounds, AGS 3.2 introduces a new sound system and Densming's tutorials were made before that.
It is explained in Other Features -> Music and sound

In other words, and I'm almost sorry for having to keep mentioning it, but you keep making mistakes that suggest you actually didn't do the tutorial, or at least didn't give it enough time to sink in.

Slow down and take your time.

And if the current manual states something different than a months old video tutorial done by a user, guess which one to follow ;)

suicidal pencil

Quote from: Khris on Tue 28/06/2011 11:43:28
(We're hijacking this thread btw...)

::)

If this thread was a train, it got hijacked and subsequently ran off the rails. And it's still going.

Quote from: ToonloonPlaySound command featured in densming's videos, just doesn't work for me...

If you're using the latest version of AGS I'm not surprised. PlaySound() is obsolete and doesn't work anymore. To play a sound, you simply type the name of the sound file and add ".Play;" to the end of it.

Just as an example, here's how some sounds in one of my games is played:
Code: ags

function PlayRicochet()
{
  int RicoNum = Random(4);
  if(RicoNum == 0) aRic1.Play();
  else if(RicoNum == 1) aRic2.Play();
  else if(RicoNum == 2) aRic3.Play();
  else if(RicoNum == 3) aRic4.Play();
  else aRic5.Play();
  return 0;
}


The sound files themselves are just 'Ric1' to 'Ric5' and when importing them in, AGS automatically adds the 'a' to the beginning of the name.

Of course, if you still wanted to be able to use PlaySound() then you'd have to go into the General Settings of your game, and change 'Enforce new-style audio scripting' to false (second from the top in the 'Backwards Compatibility' section)

edit: dammit dammit dammit Khris! You ninja'd me >:/ (why does this keep happening? *sob* )

Toonloon

Thanks guys. I'm sure you're right about the tutorials, but as I pointed out, not all the information I come across is up to date, or easy to follow.

I appreciate your patience.

Sickened

Hey guys, sorry for the late reply. So from what I understand so far, the best way to go about video formats is to convert the video to an OGG format, and then just rename it to OGV? But I think the big thing is, I found the "PlayVideo" code and everything, but where does my video need to be for it to play? If you want to play a SOUND in game, you would import the sound into the side panel and simply type the name into the code or something along those lines, but there's no Video panel on the side so I guess that's where I'm a little confused. I appreciate your feedback guys.

Khris

http://www.adventuregamestudio.co.uk/manual/PlayVideo.htm

QuoteThese types of video cannot be included into the game EXE, so you will have to place them separately in the Compiled folder for them to work.

SMF spam blocked by CleanTalk