Play Video Element from Screens

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Play Video Element from Screens

#1 Post by mitoky »

Hello!

Since i had a bit to think of how to play movies in screens, not as part of it but simply to rewatch (like in otome games, for example), i though i could share the code.

First of all, the movie is not part of the screen you call it from itself, but in a seperate screen on its own. So all you need to show it is the movie screen and a button somewhere to show it from in your menu. So the screen where the button is doesnt matters. It can be in your main menu, in an extras screen or anywhere else. It also can be any button.

For this example i made a simple extras screen from which we call a opening movie.

Code: Select all

screen extras():

    add "bg.png"
    tag menu
   
    ##  The button to call the movie. 
    textbutton _("Opening") xalign 0.5 yalign 0.5 action ShowMenu("opening_movie")

    textbutton _("Return") xalign 1.0 yalign 1.0 action Return()
And now to our actual movie screen.

When showed, the movie immediatly plays at full size.
There is no back button, instead when clicking anywhere on the screen the movie will stop playing and jump back to where you came from (in our example, it will go back to the extras screen.) Otherwise, if you let it run till the end, once done, it will too jump back.

The code can be copy/pasted, simply follow the instructions:

Code: Select all

## Black Image
image black = "#000"

screen opening_movie():

    ## In case movie loads, ensures screen isnt empty.
    add "black"
    tag menu
    
    ## Change Size according to your movie size (x, y). Movie size should be the same as your game-screen size for this to cover the whole screen!
    add Movie(size=(1920, 1080))

    ## Replace Opening.webm with your movie path/name.
    on "show" action [Play("movie", "Opening.webm", loop=False), Stop("music")]

    ## Replace MainMenuMusic.ogg with your main menu music path/name.
    on "hide" action [Stop("movie"), Play("music", "MainMenuMusic.ogg")]

    ## Replace Opening.webm with your movie path/name.
    on "replace" action [Play("movie", "Opening.webm", loop=False), Stop("music")]
 
    ## Replace MainMenuMusic.ogg with your main menu music path/name.
    on "replaced" action [Stop("movie"), Play("music", "MainMenuMusic.ogg")]

    button:
        xysize (config.screen_width, config.screen_height)
        ## Change screen name to where you came from.
        action ShowMenu("extras")

    ## Replace 120 with the lenght of your movie (in seconds) &  change screen name to where you came from.
    timer 120 action ShowMenu("extras")
If you did everything right, it should work (:
For more than one movie or to make a whole gallery for movies, you simply make a screen for each movie seperately and a button for each to show the screen (like in the example above).

If something doesnt works or your have any questions, feel free to ask!
I hope this helps!

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Play Video Element from Screens

#2 Post by Imperf3kt »

Ren'Py also includes a replay functionality.

https://www.renpy.org/doc/html/rooms.html#replay
Which may be of interest
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: No registered users