Playing bink movies

Help bring our custom Ages to life! Share tips and tricks, as well as code samples with other developers.

Playing bink movies

Postby D'Lanor » Sat Apr 19, 2008 10:32 am

Here is an example that shows how to play a bink movie. This plays the movie on top of the current scene. The problem with that is that any action from the player can mess up the movie so you'll see a lot of input actions disabled in this example. The movie can be interrupted by pressing escape.

Although the code mentions "fade" several times there isn't any fading. If you want to see an example which truly fades out the scene and brings up the standard movie background you can take a look at xOptionsMenu.py from python.pak.

Note: I copied and pasted this together from code I have used previously. It is not tested in this form so there may still be errors.

Code: Select all
from Plasma import *
from PlasmaTypes import *
from PlasmaKITypes import *
import os
import PlasmaControlKeys
actClickable = ptAttribActivator(1, 'Clickable trigger')
gMovie = None
gWasMuted = 0
kMovieName = 'avi/Intro1.bik'
kGameFadeOutID = 1
kGameFadeOutSeconds = 0.2
kMovieFadeInID = 2
kMovieFadeInSeconds = 0.2
kMovieFadeOutID = 3
kMovieFadeOutSeconds = 0.2

class MoviePlayer(ptModifier,):

    def __init__(self):
        ptModifier.__init__(self)
        self.version = 1



    def OnNotify(self, state, id, events):
        if (id == actClickable.id):
            if (PtWasLocallyNotified(self.key) and state):
                PtAtTimeCallback(self.key, kGameFadeOutSeconds, kGameFadeOutID)



    def OnTimer(self, id):
        global gMovie
        global gWasMuted
        if (id == kGameFadeOutID):
            try:
                os.stat(kMovieName)
            except:
                PtDebugPrint('MoviePlayer: no movie!!!', level=kDebugDumpLevel)
                return
            PtDebugPrint('MoviePlayer: start showing movie', level=kDebugDumpLevel)
            PtSendKIMessage(kDisableKIandBB, 0)
            PtSetGlobalClickability(0)
            PtDisableAvatarCursorFade()
            PtDisableMouseMovement()
            PtDisableMovementKeys()
            audio = ptAudioControl()
            if audio.isMuted():
                gWasMuted = 1
            else:
                gWasMuted = 0
                audio.muteAll()
            gMovie = ptMoviePlayer(kMovieName, self.key)
            #you can play with opacity here
            gMovie.setOpacity(0.6)
            gMovie.playPaused()
            PtAtTimeCallback(self.key, kMovieFadeInSeconds, kMovieFadeInID)
        elif (id == kMovieFadeInID):
            PtDebugPrint('MoviePlayer: roll the movie', level=kDebugDumpLevel)
            if (type(gMovie) != type(None)):
                gMovie.resume()
                PtEnableControlKeyEvents(self.key)
        elif (id == kMovieFadeOutID):
            PtDebugPrint('MoviePlayer: done', level=kDebugDumpLevel)
            if (type(gMovie) != type(None)):
                PtDebugPrint('MoviePlayer: stop the movie', level=kDebugDumpLevel)
                gMovie.stop()
                gMovie = None
            PtDisableControlKeyEvents(self.key)
            if (not gWasMuted):
                audio = ptAudioControl()
                audio.unmuteAll()
            PtEnableMovementKeys()
            PtEnableMouseMovement()
            PtEnableAvatarCursorFade()
            PtSetGlobalClickability(1)
            PtSendKIMessage(kEnableKIandBB, 0)



    def OnMovieEvent(self, movieName, reason):
        PtDebugPrint(('MoviePlayer: got movie done event on %s, reason=%d' % (movieName, reason)), level=kDebugDumpLevel)
        if gMovie:
            PtAtTimeCallback(self.key, kMovieFadeOutSeconds, kMovieFadeOutID)



    def OnControlKeyEvent(self, controlKey, activeFlag):
        if (controlKey == PlasmaControlKeys.kKeyExitMode):
            PtDebugPrint(('MoviePlayer: escape key hit'), level=kDebugDumpLevel)
            if gMovie:
                PtAtTimeCallback(self.key, kMovieFadeOutSeconds, kMovieFadeOutID)



#paste glue section here

"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Playing bink movies

Postby Nek'rahm » Sat Apr 19, 2008 10:36 am

dude this is AWESOME

I always though, why not have cinematics before starting where you get to talk to people ingame (like NPCs)

I imagined that if a new Uru were made, being able to interact with NPCs in this way would be killer :D
Nek'rahm
 
Posts: 461
Joined: Mon Nov 19, 2007 2:53 pm

Re: Playing bink movies

Postby andylegate » Sat Apr 19, 2008 10:37 am

Great! Going to give it a try now.
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Playing bink movies

Postby Nek'rahm » Sat Apr 19, 2008 10:39 am

Dude guys, could we impliment voice acting INTO these movies? That'd be wicked. Have messages play (like the Kirel one from RAWA) and yet have a panoramic video where it shows your avie listening and pondering.

That'd be absolutely killer.
Nek'rahm
 
Posts: 461
Joined: Mon Nov 19, 2007 2:53 pm

Re: Playing bink movies

Postby andylegate » Sat Apr 19, 2008 10:43 am

Those are very interesting, and would be great. Right now I'm concentrating on something simpler, related to our discussion about panorama linking book panels, and the flyby video you see in other myst games when you link.

I'm thinking that if I add this to my linking book template in the Age that you link from, that it will execute this, then follow the rest for the link. Have to see if this will all work first though.

But yes, I can see many applications for this.
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests