[solved] Is there a way I can let the player choose the background they want?

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.
Post Reply
Message
Author
User avatar
Nanahs
Veteran
Posts: 297
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

[solved] Is there a way I can let the player choose the background they want?

#1 Post by Nanahs » Sun Nov 04, 2018 9:08 am

Like, in the begining of the game there would be something like this:

Image

And the person can choose the bedroom they want.

Code: Select all

label chapter1:
    scene bedroom
Then whenever it's "scene bedroom", it would show the bedroom the person chose.

I'm not sure if something like this is possible. I couldn't think of any code that could make it be a variable.
I think it's not possible, but I wanted to ask you that have more experience in coding.

Thanks :)
Last edited by Nanahs on Sun Nov 04, 2018 12:13 pm, edited 1 time in total.

User avatar
IrinaLazareva
Veteran
Posts: 387
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: IKG
Location: St.Petersburg, Russia
Contact:

Re: Is there a way I can let the player choose the background they want?

#2 Post by IrinaLazareva » Sun Nov 04, 2018 10:32 am

For example, there are three images: beda.jpg, bedb.jpg, bedc.jpg.

Code: Select all

default xch = 'a'
image bedroom = 'bed[xch].jpg'

screen choscene():
    text 'Choose your destiny' align(.5, .2)
    hbox at truecenter:
        spacing 10
        imagebutton idle im.FactorScale('beda.jpg', .3) action SetVariable('xch', 'a'), Return()
        imagebutton idle im.FactorScale('bedb.jpg', .3) action SetVariable('xch', 'b'), Return()
        imagebutton idle im.FactorScale('bedc.jpg', .3) action SetVariable('xch', 'c'), Return()

label start:
    call screen choscene
    scene bedroom
    t 'Ok'
    return
https://renpy.org/doc/html/displayables ... actorScale
https://renpy.org/doc/html/screen_actio ... etVariable


Other way: to use Layered Images, by analogy...
https://renpy.org/doc/html/layeredimage ... red-images
There is a light at the end of the tunnel, just pray it's not a train.

___
TODO: unresolved/нерешённое

User avatar
Nanahs
Veteran
Posts: 297
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: Is there a way I can let the player choose the background they want?

#3 Post by Nanahs » Sun Nov 04, 2018 12:12 pm

IrinaLazareva wrote:
Sun Nov 04, 2018 10:32 am
For example, there are three images: beda.jpg, bedb.jpg, bedc.jpg.

Code: Select all

default xch = 'a'
image bedroom = 'bed[xch].jpg'

screen choscene():
    text 'Choose your destiny' align(.5, .2)
    hbox at truecenter:
        spacing 10
        imagebutton idle im.FactorScale('beda.jpg', .3) action SetVariable('xch', 'a'), Return()
        imagebutton idle im.FactorScale('bedb.jpg', .3) action SetVariable('xch', 'b'), Return()
        imagebutton idle im.FactorScale('bedc.jpg', .3) action SetVariable('xch', 'c'), Return()

label start:
    call screen choscene
    scene bedroom
    t 'Ok'
    return
https://renpy.org/doc/html/displayables ... actorScale
https://renpy.org/doc/html/screen_actio ... etVariable


Other way: to use Layered Images, by analogy...
https://renpy.org/doc/html/layeredimage ... red-images
Oh! That's so nice! Thank you so much! :)

User avatar
IrinaLazareva
Veteran
Posts: 387
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: IKG
Location: St.Petersburg, Russia
Contact:

Re: [solved] Is there a way I can let the player choose the background they want?

#4 Post by IrinaLazareva » Sun Jan 13, 2019 1:57 pm

Nanahs wrote:
Fri Jan 11, 2019 5:27 pm
A little help?
between textbutton's action and imagebutton's action is no special difference.

https://renpy.org/doc/html/screens.html#imagebutton
https://renpy.org/doc/html/screens.html#textbutton
https://renpy.org/doc/html/screens.html#button

Code: Select all

screen choscene():
    modal True
    text 'Choose your bedroom.' align(.5, .05)
    grid 2 2 at truecenter:
        spacing 100
        add im.FactorScale('beda.jpg', .3)
        add im.FactorScale('bedb.jpg', .3)        
        add im.FactorScale('bedc.jpg', .3)        
        add im.FactorScale('bedd.jpg', .3)
    textbutton 'Anna\'s bedroom' action SetVariable('xch', 'a'), Return() align(.3, .47)
    textbutton 'Susan\'s bedroom' action SetVariable('xch', 'b'), Return() align(.7, .47)
    textbutton 'Other\'s bedroom' action SetVariable('xch', 'c'), Return() align(.3, .95)
    textbutton 'Just bedroom' action SetVariable('xch', 'd'), Return() align(.7, .95)
The code was tested for (1280, 720) display resolution. So need some tweaking with align() and spacing.
https://renpy.org/doc/html/screens.html#add
https://www.renpy.org/doc/html/screens.html#grid <<<< (!)

P.S. Ideally, it is necessary to replace:

Code: Select all

        add im.FactorScale('beda.jpg', .3)
with:

Code: Select all

        add 'beda_small.jpg'
and etc...
Where beda_small.jpg - the reduced copy of the main image beda.jpg
(It will increase capacity.)

P.P.S. I strongly recommend to begin to read documentation and tutorial game.

{Disappears}
There is a light at the end of the tunnel, just pray it's not a train.

___
TODO: unresolved/нерешённое

User avatar
Nanahs
Veteran
Posts: 297
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: [solved] Is there a way I can let the player choose the background they want?

#5 Post by Nanahs » Sun Jan 13, 2019 7:47 pm

IrinaLazareva wrote:
Sun Jan 13, 2019 1:57 pm
Nanahs wrote:
Fri Jan 11, 2019 5:27 pm
A little help?
between textbutton's action and imagebutton's action is no special difference.

https://renpy.org/doc/html/screens.html#imagebutton
https://renpy.org/doc/html/screens.html#textbutton
https://renpy.org/doc/html/screens.html#button

Code: Select all

screen choscene():
    modal True
    text 'Choose your bedroom.' align(.5, .05)
    grid 2 2 at truecenter:
        spacing 100
        add im.FactorScale('beda.jpg', .3)
        add im.FactorScale('bedb.jpg', .3)        
        add im.FactorScale('bedc.jpg', .3)        
        add im.FactorScale('bedd.jpg', .3)
    textbutton 'Anna\'s bedroom' action SetVariable('xch', 'a'), Return() align(.3, .47)
    textbutton 'Susan\'s bedroom' action SetVariable('xch', 'b'), Return() align(.7, .47)
    textbutton 'Other\'s bedroom' action SetVariable('xch', 'c'), Return() align(.3, .95)
    textbutton 'Just bedroom' action SetVariable('xch', 'd'), Return() align(.7, .95)
The code was tested for (1280, 720) display resolution. So need some tweaking with align() and spacing.
https://renpy.org/doc/html/screens.html#add
https://www.renpy.org/doc/html/screens.html#grid <<<< (!)

P.S. Ideally, it is necessary to replace:

Code: Select all

        add im.FactorScale('beda.jpg', .3)
with:

Code: Select all

        add 'beda_small.jpg'
and etc...
Where beda_small.jpg - the reduced copy of the main image beda.jpg
(It will increase capacity.)

P.P.S. I strongly recommend to begin to read documentation and tutorial game.

{Disappears}
Oh, thank you so much! It was really confusing for me.
I'll definitely study more the documentation and python.
Thanks :)

Post Reply

Who is online

Users browsing this forum: Bing [Bot]