Screenshots?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Screenshots?

#1 Post by Alera »

I am getting crazy ideas in my head again about codes. So I have this question- is it possible to have RenPy make a screenshot of your game screen and to define and use the image in the game later? It should be possible, like for the save/load thingies, right? But-how exactly? ^^lll And something in addition- is it possible to make it screenshot just part of the screen? Or somehow to crop the defined image later, I don't know...

I'm sorry that I'm not very good at explaining but I hope that you got what I mean. ^^lll Thank you~
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

User avatar
SilverxBlue
Miko-Class Veteran
Posts: 962
Joined: Sat Jan 01, 2011 1:22 pm
Completed: Caught in Between: A childhood prologue
Projects: MDLS, Alice Hunt(Temporarily on-hold), The Guardian's Spell and one other unannounced thing.
Location: Philippines
Contact:

Re: Screenshots?

#2 Post by SilverxBlue »

It is possible, all you have to do is press the letter "S" in the part you want to have a screenshot on.
Then look at your Renpy folder and it should be there.

Sorry, if this is not what you're asking for... I'm kinda slow. ^^:
Image Image
"A fool who doesn't think is more foolish than a fool who foolishly thinks." - Franziska Von Karma
Weeeeeee~
不愉快です !!!

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Screenshots?

#3 Post by Alera »

Wow, really?! Thanks! :'D Very useful~

Though! Do you think I could make some button for that? Like at some point in my game, the player has to take a screenshot to continue because will need it later or something like that?
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

bink
Regular
Posts: 49
Joined: Sat Jul 09, 2011 4:34 pm
Contact:

Re: Screenshots?

#4 Post by bink »

I wrote a camera function for a game before.
The player can pick the camera item from their inventory and it will display a camera complete with a menu that contains images taken before and such. You can then take a photo and it will be saved for later use.
Is that what you want it to do? I could share my code for that, I guess.

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Screenshots?

#5 Post by Alera »

@bink

Yes,something very similar to that! >w< I think if you share- I could adapt it to my case. Would be really wonderful!
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

User avatar
SilverxBlue
Miko-Class Veteran
Posts: 962
Joined: Sat Jan 01, 2011 1:22 pm
Completed: Caught in Between: A childhood prologue
Projects: MDLS, Alice Hunt(Temporarily on-hold), The Guardian's Spell and one other unannounced thing.
Location: Philippines
Contact:

Re: Screenshots?

#6 Post by SilverxBlue »

Alera wrote:Wow, really?! Thanks! :'D Very useful~

Though! Do you think I could make some button for that? Like at some point in my game, the player has to take a screenshot to continue because will need it later or something like that?
No problem! Glad to be of help!
For your own game I'm sure you can use it, but for other games that you are playing, I'm not so sure. :/
Image Image
"A fool who doesn't think is more foolish than a fool who foolishly thinks." - Franziska Von Karma
Weeeeeee~
不愉快です !!!

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Screenshots?

#7 Post by Alera »

SilverxBlue wrote:
No problem! Glad to be of help!
For your own game I'm sure you can use it, but for other games that you are playing, I'm not so sure. :/

Aw, of course- I just want to add it as a feature in my own game. ^^
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

bink
Regular
Posts: 49
Joined: Sat Jul 09, 2011 4:34 pm
Contact:

Re: Screenshots?

#8 Post by bink »

Here are the two most important functions for this, including comments on what every line does and why. I didn't include the functions that build the camera UI and everything. Didn't want this post to be two pages long, and you probably have your own ideas for those already.

Code: Select all

    #This function is called by the UI button when it is clicked.
    def camera_take_photo():

        # First we call the actual photo taking function and save the return value in newPhoto

        newPhoto = renpy.invoke_in_new_context(_camera_take_photo)

        # Now we display a transition that looks like a camera flash. This makes it look really good. ;)

        renpy.transition(Fade(0,0,0.5,color=(255,255,255,255)))

        # The saved photo name is now added to photos. Photos is a list that keeps track of the photos
        # we have already taken. Since the photoname is also the filename, use this name to load the
        # photos.

        photos.append(newPhoto)

        # Now we return to the parent function. In this case it's the one responsible for building the camera
        # UI, but it might be different in your case. You might not need this at all.

        return "photo_taken"
    
    # This function is called by the one above and takes the actual photo. This is where the magic happens.    
    def _camera_take_photo():

        # First we initiate an interaction that doesn't display overlays and windows. We don't want them in our photo.
        # So we create a pausebehavior that pauses the game for 0.0 seconds and then continues. That's enough time to
        # take the photo. Then we start the interaction.

        ui.pausebehavior(0.0)
        ui.interact(suppress_overlay=True, suppress_window=True)

        # Now we take a screenshot, 800x600 in this case, and get the screenshots image data from the corresponding
        # variable.

        renpy.take_screenshot((800,600))
        photo = renpy.game.interface.get_screenshot()

        # Now we create the filename. In this case, we use the MD5 hash of the image. This means that each image will
        # have a unique name and that no image can exist twice. This saves disk space if you take the same photo twice
        # by accident. It will overwrite the first one.

        photoname = hashlib.md5(photo).hexdigest()

        # We now define the directory we want to save the file to. I chose /game/pho/, but it's up to you.

        photodir = config.basedir + "/game/pho/"

        # We create it if it doesn't exist. Somebody might have deleted it by accident and that would probably cause
        # the game to crash. We don't want that.

        if(os.path.isdir(photodir) == False):
            os.mkdir(photodir)

        # Now we open the file. This will automatically create it if it doesn't exist already. Then we write the image
        # data into the file and close it again.

        f = open(photodir + photoname + ".png","wb")
        f.write(photo)
        f.close()

        # Now we just return the name and we're done here.

        return photoname
Be aware that you can't just copy and paste this. There are some modules you will have to import too, like hashlib and os.

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Screenshots?

#9 Post by Alera »

Thank you very-very much @bink!!! >w< *resists to glomp* The comments are an awesome addition!

I'll try to play around with this code later today. If I get any questions or errors then- I'll but again. XD *shot*
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Screenshots?

#10 Post by Soraminako »

That code is awesome, and very useful! *_* Would it be ok for me to take it as well? :D

And if yes, what are hashlib and os? ^^; (Please pardon my noobness. ^^; )

And a little question about screenshots, related to this thread also: If I save a screenshot with the "s" key, it puts them in the ren'py folder for me and I can see it, while I'm making the game, but it doesn't save them in the game folder itself, so I was wondering, once the game is released will the players also be able to save screenshots using that method?
Where will those screenshots show up then? In their save folder or some place like that? :?

Thank you so much in advance, for your reply.
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

bink
Regular
Posts: 49
Joined: Sat Jul 09, 2011 4:34 pm
Contact:

Re: Screenshots?

#11 Post by bink »

Soraminako wrote:That code is awesome, and very useful! *_* Would it be ok for me to take it as well? :D

And if yes, what are hashlib and os? ^^; (Please pardon my noobness. ^^; )
Sure, feel free to use it, I don't mind. As long as your game turns out to be awesome, that's fine. :P

hashlib and os are Python modules that are used to add more functionality. To keep things clean, those are not included by default, because you probably won't need them.
To include them in your script, you have to import them.
In a Python block (where the camera functions should already be anyway) put this:

Code: Select all

import os, hashlib
That will import them both and make the script work.

Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Screenshots?

#12 Post by Soraminako »

bink wrote: Sure, feel free to use it, I don't mind. As long as your game turns out to be awesome, that's fine. :P

hashlib and os are Python modules that are used to add more functionality. To keep things clean, those are not included by default, because you probably won't need them.
To include them in your script, you have to import them.
In a Python block (where the camera functions should already be anyway) put this:

Code: Select all

import os, hashlib
That will import them both and make the script work.
Thank you! :D
And wow, importing them seems easier than I expected.

And if you don't mind sharing more of your code, for the sake of noobs like me who stand little to no chance of figuring out how to build the camera UI itself on our own, could you also show how you made yours? ^^; (If you don't mind.)
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Screenshots?

#13 Post by Soraminako »

Hi again... I tried using the camera code today but it said "photos" wasn't defined. (From the "photos.append(newPhoto)" line.)

I'm not sure (to be exact, I don't have even the slightest idea) how to edit the code to make it work, so if you happen to see this and be able to drop by and help, it would be wonderful. ^^;

I also wasn't sure how to call the function for camera_take_photo either since I didn't hear back from you, but I'm using the following code:

Code: Select all

    $ ui.imagebutton("gfx/littlecamera1.png", "gfx/littlecamera2.png", camera_take_photo(), ypos=350, xpos=350) 
It calls it, but then crashes the game due to the photos not being defined.

Is there a problem with my ui or is that the proper way of calling something like that?

I'm still so noobish when it comes to this kind of thing.... ._.
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

bink
Regular
Posts: 49
Joined: Sat Jul 09, 2011 4:34 pm
Contact:

Re: Screenshots?

#14 Post by bink »

photos is just a list of photos that were already taken. I defined it right after the start label begins:

Code: Select all

label start:
    $ photos = [] # initialize empty photo list
The code you're using to call it looks fine to me. Try adding the list and check if it works.

Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Screenshots?

#15 Post by Soraminako »

Thank you so much! It's working perfectly!
Wow I feel dumb for not realizing sooner it was just that that was needed. XD But I'm so glad that now it works so well! :D


Edit: I spoke too soon. ^^;

I hadn't noticed before but I have a weird problem, the camera takes the pics when I reach the scene in the game where the button should show up. It doesn't wait for me to click, it just automatically takes pics when you reach the line of the code where the button should show up.

Clearly, I'm doing something wrong. ^^; I've tried modifying the code but it keeps doing it. ^^; Any idea of some other way I could trigger the camera when I want?

I also tried this, but it kept crashing:

Code: Select all

    vbox xpos 575 ypos 3:
        hbox:
            text "Save image?" size 12 outlines [(0, "#f1acad", 0, 0)]
            textbutton "Ok" action camera_take_photo()
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

Post Reply

Who is online

Users browsing this forum: Google [Bot], Syrale