Best practice for game intro, ingame movie playback.

Advanced game related topics
Krix
User
User
Posts: 65
Joined: Fri Mar 11, 2005 6:24 pm
Location: Toronto

Best practice for game intro, ingame movie playback.

Post 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!
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

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

Post 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?
Image
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1252
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

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

Post 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.
Image Image
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post by IdeasVacuum »

...you could perhaps display a regular window playing the movie?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

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

Post 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()
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Krix
User
User
Posts: 65
Joined: Fri Mar 11, 2005 6:24 pm
Location: Toronto

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

Post by Krix »

Thanks guys! I appreciate it!
Post Reply