Page 1 of 1

Playing bink movies

PostPosted: Sat Apr 19, 2008 10:32 am
by D'Lanor
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


Re: Playing bink movies

PostPosted: Sat Apr 19, 2008 10:36 am
by Nek'rahm
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

Re: Playing bink movies

PostPosted: Sat Apr 19, 2008 10:37 am
by andylegate
Great! Going to give it a try now.

Re: Playing bink movies

PostPosted: Sat Apr 19, 2008 10:39 am
by Nek'rahm
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.

Re: Playing bink movies

PostPosted: Sat Apr 19, 2008 10:43 am
by andylegate
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.