Page 1 of 1

Best practice for game intro, ingame movie playback.

Posted: Wed Aug 13, 2014 7:48 am
by Krix
Hi,

What's the best practice to play video in the beginning of a 2D game and in between levels? Do I have to open a new screen for the movie, and then close it and open a new screen for the game(play) itself? Once the video is done, how do I jump automatically to the (let's say) main game loop? The Movie.pb example plays the movie once and then I have to manually close the window. Is there any command to detect that the movie is done, or do I have to give the exact length of the movie manually and make it stop after the time is up?

For example, I have an intro for Waponez II and I want to play it before the game starts. What's the best practice to do that? Code please!

Thanks!

Re: Best practice for game intro, ingame movie playback.

Posted: Wed Aug 13, 2014 9:00 am
by Bananenfreak
Hmm, you´re asking for code, here´s code:

Code: Select all

InitMovie()
mov = LoadMovie()
PlayMovie(mov, ScreenID())
Repeat
  ExamineKeyboard()
  RenderWorld()
  FlipBuffers()
Until KeyboardReleased(#PB_Key_Esc) Or MovieStatus(mov) = 0       ;I´m not sure with that, a finished movie isn´t documented.
FreeMovie(mov)
There is another possibility. You copy each frame of your movie and fill a sprite with it (I´m interested in this solution, too).
Or is it possible to use a movie in a materialscript?

Re: Best practice for game intro, ingame movie playback.

Posted: Wed Aug 13, 2014 1:39 pm
by Paul
One of the coolest features that was removed in 5.20LTS for some reason was the ability to render your movie frames to a sprite and then manipulate it like any other sprite.
Sure would be nice if this was put back in... or at least something very similar.

Re: Best practice for game intro, ingame movie playback.

Posted: Wed Aug 13, 2014 1:41 pm
by IdeasVacuum
...you could perhaps display a regular window playing the movie?

Re: Best practice for game intro, ingame movie playback.

Posted: Wed Aug 13, 2014 6:03 pm
by DK_PETER
Perhaps something like this?

Code: Select all

InitSprite():InitKeyboard():InitMovie()

Declare.i DoMovie()
Declare.i DoGame()
Declare.i DoMovie2()

OpenWindow(0, 0, 0, 1024, 768, "Game/movie", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, 0, 0, 0, #PB_Screen_SmartSynchronization)


Procedure.i DoMovie()
  Protected mov.i, Done.i
  Done = 0
  mov = LoadMovie(#PB_Any, "E:\1.avi")
  ResizeMovie(mov, 0, 0, 1024,768)
  PlayMovie(mov, ScreenID())
  Delay(1000)  ;<---delay To make sure, that moviestatus isn't 0 right away

  Repeat
    Repeat:ev = WindowEvent():Until ev = 0
    
    If MovieStatus(Mov) <= 0
      done = 1
    EndIf
    
  Until done = 1
  FreeMovie(mov)
  ProcedureReturn 0
EndProcedure

Procedure.i DoGame()
  
  Repeat
    ClearScreen(0)
    StartDrawing(ScreenOutput())
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(100,100,"Game Screen",$FF00FF)
    StopDrawing()
    
    Repeat:ev = WindowEvent():Until ev = 0
    
    ExamineKeyboard()
    
    FlipBuffers()
    
    If KeyboardReleased(#PB_Key_Space)
      ret = DoMovie2()
    EndIf
    
  Until KeyboardPushed(#PB_Key_Escape)
  
EndProcedure

Procedure.i DoMovie2()
  Protected mov.i, Done.i
  Done = 0
  mov = LoadMovie(#PB_Any, "E:\2.avi")
  ResizeMovie(mov, 0, 0, 1024,768)
  PlayMovie(mov, ScreenID())
  Delay(1000)  ;<---delay To make sure, that moviestatus isn't 0 right away

  Repeat
    Repeat:ev = WindowEvent():Until ev = 0
    
    If MovieStatus(Mov) <= 0
      done = 1
    EndIf
    
  Until done = 1
  FreeMovie(mov)
  ProcedureReturn 0
EndProcedure

ret = DoMovie()
DoGame()

Re: Best practice for game intro, ingame movie playback.

Posted: Wed Aug 13, 2014 10:00 pm
by Krix
Thanks guys! I appreciate it!