How to add cutscenes to your game

Hello people,

I am making my first steps into java game developing, and I have kind of a prototype of a game. I wanted to add a small intro video (and cut scenes in the future) before the menu and the game launches, and I am finding that is not easy.
I have read about JMF, and about javaFX and Xuggler to add a video file… but everything looks quite complex, and not everybody looks happy with their solutions.

So, my question is, how do you add cutscenes to your games? Of course if it is something simple/small I can directly animate the frames, as I do with sprites, but I guess that’s not the solution for comples/long cutscenes. To be able of add a video file and play it before the game, or en between will be awesome…

I don’t want to re invent the wheel and I want to solve this as easy as possible! I guess most of you have wanted to add some cutscenes or intros to your games…

Thanks a lot!

Note remarkable lack of video in Java based games. This is because… Java video has been stunningly ignored for the past decade. It is not at all trivial to try and do. If this is your first foray into Java game developing I’d simply give up on this particular thing now and carry on with the rest of your game, which will probably have you pulling your hair out anyway. Come back to it when the game is finished!

Cas :slight_smile:

Thanks a lot Cas, I will follow your advice!

Hi

Look at FreeCol, it uses a cutscene. There is an attempt of providing build-in video support in JogAmp, it uses FFMEG and libAV under desktop environments, something else under Android. Please ask Sven to explain to you how to use it, rather post your question on the official JogAmp forum. Best regards.

Edit.: Someone here succeeded in using JMC (from JavaFX).

Edit2.: In the worst case, you can try to use a command to run the player.

There are quite a lot of threads here about this topic, most started by me.

Like Cas said, its a very sad part of Java - so only come back to this topic if you really really need video.

I’m using VLCJ.

Hey Cero, yes I have read your threads about this, and that’s how I know it is hard.

Well the point it is that I really need cut scenes… I was making a point and click adventure, so the cut scenes were supposed to be a very important part. But if it is to difficult to make it work, well, I have another projects in mind, so I can start making another videogame that don’t need any video.
And let’s see if in the future I want to make the point and click adventure in java or not!

Maybe you will be okey with other kinds of “cutscenes”, where you just make the players/characters walk in you window, playing something like a real-time rendered video :slight_smile:

Of course there are many popular point and click without video… But I can understand that you want video in story based game.
Basically VLCJ works. Its just a little hassle to include everything for every platform. But VLC works on every platform, and its very reliable.
Only minor problem is, which might disappear soon, that VLCJ is still GPL, which forces your whole sourcecode to be GPL.
Even if that happened, nobody cares about source code anyway…

So that rules out VLCJ for two reasons then.

I just decided to give it a shot: using VLC (not VLCJ) to play the audio in realtime, and streaming the video frames to 1 file, which is continuously overwritten. VLC takes care of the syncing of video/audio. The only thing the Java app has to do is poll the dump-file, read it, and display it.

Obviously the disk I/O becomes the bottleneck, so to playback HD @ 25fps, I needed the dump-file to be on a RAM-disk.

It’s only 150 lines of code:
http://pastebin.java-gaming.org/54a6b0d341c
It could be a lot shorter, but I decided to use 3 threads: one for I/O, one for decoding, one for displaying. This resulted in smoother playback. It effortly played back any media file I threw at it.

Because Java’s ImageIO.read is rather slow for PNG and JPEG, I used BMP for the dump-file for best performance. javaw.exe used about half the cpu cycles vlc.exe used, which to me seems good enough.

According to the commandline options, we can provide function-pointers, so VLC can simply call a C function, providing the pixels, which we can copy/map into a texture, or an awt image. To me, this seems like something you can code in a rainy afternoon, so why are we all giving up on ‘java video’ ?

Erm… could you give me a Java 6 version? ;D

It’s full of dependencies anyway, so in the current state it’s useless. The requirement of a ramdisk adds insult to injury, don’t waste your time on it :slight_smile:

It would be acceptable if Windows natively supported the creation of ramdisks. I’m using ImDisk (freeware) to create a 8MB ramdisk that holds the file. It’s still inefficient, as it simulates a NTFS partition, which adds quite a bit of overhead, so it’s never going to be as fast as IPC (inter process communication).

Yeah I know. I didn’t even wanted to use it for anything. But I really like the idea. Craciest Idea evaaar :smiley:

Xuggler looks like a good choice for Java video. Xuggler and FFmpeg are both LGPL (unlike both VLC/VLCJ which are GPL), seems easy enough to setup and have seen it used in a few big Java projects (JPCSP, Wakfu, jMonkeyEngine3, etc).

I think it’s possible in applets, I did a quick test for an applet/js/ytplayer combo which isn’t too bad -
See it here.
I believe it’s possible to hide the player controls but I didn’t get that far!

You could use Illustrator/InkScape as your animation software and create SVG files. There are a number of SVG parsers out there, and Slick even has a couple SVG animation tests that work quite well.

Alternatively you could write your own “timeline” and design your own animation through code – moving images with easing, fading in/out text, etc. over time.

What kind of intro are you going for?

I got a horrible user experience from that applet :slight_smile:

When I hit [space], it played the movie for 1 second, then it showed me the black screen again, telling me to hit [space]. I tried keeping [space] pressed, but that didn’t make it play fully either.

Strange. It is working for me, even though Adobe flash support on linux is… well… heh :smiley: dontwantstosaybadwords

Well the creator is actually flexible on the license and if you really have a problem with GPL he might change it.
Not sure what your other reason is.

I’m using VLCJ actively, integrated in my engine, works great. Using it for cut-scenes.

Is it even possible for the creator of VLCJ to make the licence something else than GPL? I know he himselfs writes that, but VLC is GPL, now how does he want to do that?

it ain’t, anymore. It’s LGPL now.
So Mark Lee said to me its probable that he is going to change VLCJ’s license too