TUTORIAL: Changing image/screen according to real time.

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
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

TUTORIAL: Changing image/screen according to real time.

#1 Post by Nanahs »

Hello guys!
I had a lot of trouble trying to figure out how to make this work properly.
I want to thank everyone who helped me and also those who are always trying to help here in this forum.

I found a simple way of changing a screen/image according to real time, and I'd like to share with you.

In my case, there's a window in a bedroom on my label scene. I wanted to change this window with sun, moon, etc (images/screens) according to morning, afternoon, evening and night (current real time).

So I started by creating an image of a window with sun outside and animated light rays.
I think there's another way to create an animated image, but I did it like this:

Code: Select all

    image morningsun:
        "sky/sun1.png"    #### the file location and name
        0.3               #### the speed the image is going to jump to the next one
        pos (355,200)     #### the position you want it in your screen
        "sky/sun2.png"
        0.3
        pos (355,200)
        "sky/sun3.png"
        0.3
        pos (355,200) 
      
        repeat           #### makes the image keep on repeating
You can do with all the images you want that way. In my case I made four different images (for morning, afternoon, evening, night).

Then you just write the label where you want it to be and this code:

Code: Select all

label bedroom:
    
    scene bedroom1   
    
    $hour = datetime.datetime.now().hour        ######### this will verify what time it currently is
    
    if hour in [6, 7, 8, 9, 10, 11]:            ######### type here the hour you want the image to be displayed
        hide image "nightsky"                   ######### I'm not sure if that's necessary, but I chose to "hide" the previous image (before the morning it would be night image)
        show image "morningsky"
        $startTime= 6                           ######### this code makes the image START at this time (not sure if this part is necessary)
        $endTime= 11                            ######### this code makes the image END at this time (not sure if this part is necessary)

    if hour in [12, 13, 14, 15, 16]:
        hide image "morningsky"
        show image "afternoonsky"
        $startTime= 12
        $endTime= 16

    if hour in [17, 18, 19]:
        hide image "afternoonsky"
        show image "eveningsky"
        $startTime= 17
        $endTime= 19
        
    if hour in [20, 21, 22, 23, 00, 1, 2, 3, 4, 5]:   
        hide image "eveningsky"
        show image "nightsky"
        $startTime= 20
        $endTime= 5


It could also be "show screen" if you wanted a screen to show up at the time, etc.

Well, that's it. That was the easiest way I found to do it.
It worked well on pc and also on android.
I hope this can help someone.

Have a nice year guys! :)

Post Reply

Who is online

Users browsing this forum: No registered users