[Solved] Cycling Through a List of Images in a Folder for Main Menu
Posted: Mon May 17, 2021 3:08 pm
Hey! I'm finally getting back into working on my game, and I figured that it might be an interesting idea to make it so the background image in my main menu cycles through different backgrounds in the game. I'm struggling a bit with accessing the folder and putting the list in my game. Here's a couple of methods that I tried:
The error here is:
So I figured that I just should've used a back slash instead of a forwards slash, but the new error only left me more confused.
...So, I tried something else.
Which was a little bit closer, I did actually get to the main menu this time instead of the code aborting right away. However, it seems like it's just listing all the files in the game and not specifically the ones in that directory as I will occasionally get the error:
Not always that specific file, but I am trying to get files only in 'images/bgs'. This game is going to be released in multiple chapters that have to be installed, and I want to make sure new backgrounds still have the potential to load so I'd rather not manually input the whole list of images if I can avoid it.
Any help with whichever method would be appreciated, thank you!
Code: Select all
init python:
import os
path = 'images/bgs'
mmBackground = os.listdir(path)
imageIndex = random.randint(0,len(mmBackground)-1)
gui.main_menu_background = mmBackground[imageIndex]
screen main_menu():
Code: Select all
WindowsError: [Error 3] The system cannot find the path specified: u'images/bgs\\*.*'
Code: Select all
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: u'images\x08gs\\*.*'
Code: Select all
define mmBackgrounds = renpy.list_files('images/bgs')
define imageIndex = renpy.random.randint(0,len(mmBackgrounds)-1)
define gui.main_menu_background = mmBackgrounds[imageIndex]
screen main_menu():
Code: Select all
Exception: Could not load image u'00compat.rpy': error ('Unsupported image format',)
Any help with whichever method would be appreciated, thank you!