Cycling images on menu
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.
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.
-
- Newbie
- Posts: 6
- Joined: Tue Dec 11, 2018 11:24 pm
- Contact:
Cycling images on menu
Hello im new at using renpy and i wanted to try something a bit more complex this time around.
I want to have the background image of the menu change every time you open the game, or cycle around like some vns that i played before.
I know the basics of the program and coding, however im not quite sure how to set it up.
I only need to cycle between like 5 images that i have already prepared.
Any help would be appreciated
I want to have the background image of the menu change every time you open the game, or cycle around like some vns that i played before.
I know the basics of the program and coding, however im not quite sure how to set it up.
I only need to cycle between like 5 images that i have already prepared.
Any help would be appreciated
- Per K Grok
- Miko-Class Veteran
- Posts: 882
- Joined: Fri May 18, 2018 1:02 am
- Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
- itch: per-k-grok
- Location: Sverige
- Contact:
Re: Cycling images on menu
You can add images to the menu screen in the screen.rpy file.ricardo456 wrote: ↑Wed Dec 12, 2018 12:22 am Hello im new at using renpy and i wanted to try something a bit more complex this time around.
I want to have the background image of the menu change every time you open the game, or cycle around like some vns that i played before.
I know the basics of the program and coding, however im not quite sure how to set it up.
I only need to cycle between like 5 images that i have already prepared.
Any help would be appreciated
Find "screen main-menu():". Below the line 'add gui.main_menu_background' you add your image ' add "yourImage1.png" '
To randomly show a different image each time you open the game you need to import a random module. You can do that in script.rpy
Code: Select all
init python:
from random import randint
You can then use this to randomly show a new image when opening the menu
Code: Select all
$ randPix = randint(1,3)
if randPix==1:
add "yourImage1.png":
elif randPix==2:
add "yourImage2.png":
else:
add "yourImage3.png":
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Cycling images on menu
Note that the above code will only generate a different (possibly the same) image each time you start the game, it won't change the menu image any other time, including when quitting or finishing the game and returning to the main menu.
To rotate the image every time the menu is shown, I use the following in one of my projects. Its technically a click to continue kind of screen and replaces the general main menu of the project, but can be adapted to suit any screen.
This cycles through the images in order, but can be made to randomise the image by adding Per K Grok's suggestion of using randint
The first section deals with adding the image to the main menu. The second section (the imagebuttons) are used to close the screen and increment the counter by one.
To rotate the image every time the menu is shown, I use the following in one of my projects. Its technically a click to continue kind of screen and replaces the general main menu of the project, but can be adapted to suit any screen.
This cycles through the images in order, but can be made to randomise the image by adding Per K Grok's suggestion of using randint
Code: Select all
init -1:
default persistent.main_menu_sprite = 1
screen main_menu():
tag menu
style_prefix "main_menu"
add gui.main_menu_background
if persistent.main_menu_sprite == 1:
add my_image_1.png
if persistent.main_menu_sprite == 2:
add my_image_2.png
if persistent.main_menu_sprite == 3:
add my_image_3.png
if persistent.main_menu_sprite == 4:
add my_image_4.png
if persistent.main_menu_sprite == 1:
imagebutton idle gui.main_menu_text hover gui.main_menu_text xpos 0 ypos 0 focus_mask True action ShowMenu("main_menu_2"), SetField(persistent, "main_menu_sprite", 2)
elif persistent.main_menu_sprite == 2:
imagebutton idle gui.main_menu_text hover gui.main_menu_text xpos 0 ypos 0 focus_mask True action ShowMenu("main_menu_2"), SetField(persistent, "main_menu_sprite", 3)
elif persistent.main_menu_sprite == 3:
imagebutton idle gui.main_menu_text hover gui.main_menu_text xpos 0 ypos 0 focus_mask True action ShowMenu("main_menu_2"), SetField(persistent, "main_menu_sprite", 4)
elif persistent.main_menu_sprite == 4:
imagebutton idle gui.main_menu_text hover gui.main_menu_text xpos 0 ypos 0 focus_mask True action ShowMenu("main_menu_2"), SetField(persistent, "main_menu_sprite", 1)
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
-
- Newbie
- Posts: 6
- Joined: Tue Dec 11, 2018 11:24 pm
- Contact:
Re: Cycling images on menu
I appreciate the quick responses, unfortunately im not too sure where everywhere goes.
So i initiate things on script, but i am kind of confused where each part of the code goes. Sorry for being a newbie. I think just them cycling in order is fine. I might actually prefer that since i want each image to show around the same number of times
So i initiate things on script, but i am kind of confused where each part of the code goes. Sorry for being a newbie. I think just them cycling in order is fine. I might actually prefer that since i want each image to show around the same number of times
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Cycling images on menu
For both given examples, the init part can go almost anywhere.
Best place is just in the screens.rpy file at the same indentation (spacing) it's at, outside other screens.
The top works fine.
An easier way may be to create a new file, call it in inits.rpy or something, and place it in there.
The rest of the code goes anywhere below screen main_menu():, so that it is included as part of that screen.
To make it a bit simpler (because it's a bit specific to the game I pulled it from), I'll try to rewrite the code I posted so it'll work without the imagebuttons, just using the default screens.rpy
I may take a whole day though, as my time to browse forums is a bit limited at the moment.
Best place is just in the screens.rpy file at the same indentation (spacing) it's at, outside other screens.
The top works fine.
An easier way may be to create a new file, call it in inits.rpy or something, and place it in there.
The rest of the code goes anywhere below screen main_menu():, so that it is included as part of that screen.
To make it a bit simpler (because it's a bit specific to the game I pulled it from), I'll try to rewrite the code I posted so it'll work without the imagebuttons, just using the default screens.rpy
I may take a whole day though, as my time to browse forums is a bit limited at the moment.
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
-
- Newbie
- Posts: 6
- Joined: Tue Dec 11, 2018 11:24 pm
- Contact:
Re: Cycling images on menu
Oh no thank you very much for your time, its great to see you are willing to put this much effort. I will try to make it work if i manage i will let you know so you don't have to spend that much time. It gives me a couple of errors mostly than my images are not defined.
Code: Select all
init -1:
default persistent.main_menu_sprite = 1
screen main_menu():
tag menu
style_prefix "main_menu"
add gui.main_menu_background
if persistent.main_menu_sprite == 1:
add Novella_Bg.jpg
if persistent.main_menu_sprite == 2:
add Lisa_Bg.jpg
if persistent.main_menu_sprite == 3:
add Fabiola_Bg.jpg
if persistent.main_menu_sprite == 4:
add Adria_Bg.jpg
if persistent.main_menu_sprite == 1:
imagebutton idle gui.main_menu_text hover gui.main_menu_text xpos 0 ypos 0 focus_mask True action ShowMenu("main_menu_2"), SetField(persistent, "main_menu_sprite", 2)
elif persistent.main_menu_sprite == 2:
imagebutton idle gui.main_menu_text hover gui.main_menu_text xpos 0 ypos 0 focus_mask True action ShowMenu("main_menu_2"), SetField(persistent, "main_menu_sprite", 3)
elif persistent.main_menu_sprite == 3:
imagebutton idle gui.main_menu_text hover gui.main_menu_text xpos 0 ypos 0 focus_mask True action ShowMenu("main_menu_2"), SetField(persistent, "main_menu_sprite", 4)
elif persistent.main_menu_sprite == 4:
imagebutton idle gui.main_menu_text hover gui.main_menu_text xpos 0 ypos 0 focus_mask True action ShowMenu("main_menu_2"), SetField(persistent, "main_menu_sprite", 1)
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Cycling images on menu
That'd be the imagebutton bit and I forgot to add quotation.
Should fix up the undefined images, but they won't cycle until the imagebuttons bit is fixed up.
I was just planning on editing the textbutton 'start' to include a set of if checks and add
SetField(persistent, "main_menu_sprite", #)
Don't have a computer to do that right now, but will try throuout the day.
Code: Select all
init -1:
default persistent.main_menu_sprite = 1
screen main_menu():
tag menu
style_prefix "main_menu"
add gui.main_menu_background
if persistent.main_menu_sprite == 1:
add "Novella_Bg.jpg"
if persistent.main_menu_sprite == 2:
add "Lisa_Bg.jpg"
if persistent.main_menu_sprite == 3:
add "Fabiola_Bg.jpg"
if persistent.main_menu_sprite == 4:
add "Adria_Bg.jpg"
I was just planning on editing the textbutton 'start' to include a set of if checks and add
SetField(persistent, "main_menu_sprite", #)
Don't have a computer to do that right now, but will try throuout the day.
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
-
- Newbie
- Posts: 6
- Joined: Tue Dec 11, 2018 11:24 pm
- Contact:
Re: Cycling images on menu
Ok you were right that does fix the image issue, unfortunately i could not make the second part work
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Cycling images on menu
The solution by Per K Grok is pretty good, and a bit simpler. Have you tried it yet?
I'm going to be really busy today, but will still try to edit things for you.
I would have done it last night, but for some unknown reason my laptop keyboard broke and now I cannot login to my laptop.
I'm going to be really busy today, but will still try to edit things for you.
I would have done it last night, but for some unknown reason my laptop keyboard broke and now I cannot login to my laptop.
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
-
- Newbie
- Posts: 6
- Joined: Tue Dec 11, 2018 11:24 pm
- Contact:
Re: Cycling images on menu
I have tried it, but cant seem to make it work well, i guess i need to give a better read to the basics, also dont rush yourself, i can still write around without this feature. Its just something i wanted to add this time around. There is a lot of writing to be done, so take all the time you need
-
- Newbie
- Posts: 6
- Joined: Tue Dec 11, 2018 11:24 pm
- Contact:
Re: Cycling images on menu
managed to make Per K Grok thing work, however it does repeat a bit much, but i guess it works well enough
Who is online
Users browsing this forum: No registered users