Multiple Images in Image Map [SOLVED]

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
drbugs
Newbie
Posts: 13
Joined: Sat Nov 14, 2020 10:27 am
Contact:

Multiple Images in Image Map [SOLVED]

#1 Post by drbugs » Sun Jan 03, 2021 6:53 pm

Apologies in advance if this is a super basic question. I had a look around but I couldn't find anything that covered this specific question, and my knowledge of coding is not strong enough for me to really figure it out myself.

I want to have an image map that has multiple versions of the background when hovering over a button.
For example:

BUTTON ONE
On hover: Background becomes image 1

BUTTON TWO
On hover: Background becomes image 2

BUTTON THREE
On hover: Background becomes image 3

etc.


I tried to mess around with the image map codes on the forum, but I'm not sure how to get more than two background options. Is there a way to do it with if or conditionswitch?
Last edited by drbugs on Mon Jan 11, 2021 6:45 pm, edited 1 time in total.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Multiple Images in Image Map

#2 Post by _ticlock_ » Sun Jan 03, 2021 10:00 pm

Hi, drbugs,

Do you want to change the background based on the hovered button?
For example you can do this:

Code: Select all

screen test_screen():
    default background_img = "background_base.jpg"
    add background_img
    vbox:
        textbutton "button 1":
            hovered [SetScreenVariable("background_img", "background_img_01.jpg"),
                With(Dissolve(0.5))]
            unhovered [SetScreenVariable("background_img", "background_base.jpg"),
                With(Dissolve(0.5))]
            action Return()
        textbutton "button 2":
            hovered [SetScreenVariable("background_img", "background_img_02.jpg"),
                With(Dissolve(0.5))]
            unhovered [SetScreenVariable("background_img", "background_base.jpg"),
                With(Dissolve(0.5))]
            action Return()
        textbutton "button 3":
            hovered [SetScreenVariable("background_img", "background_img_03.jpg"),
                With(Dissolve(0.5))]
            unhovered [SetScreenVariable("background_img", "background_base.jpg"),
                With(Dissolve(0.5))]
            action Return()

label start:
    call screen test_screen

User avatar
drbugs
Newbie
Posts: 13
Joined: Sat Nov 14, 2020 10:27 am
Contact:

Re: Multiple Images in Image Map

#3 Post by drbugs » Tue Jan 05, 2021 8:14 pm

Thanks for the code.
To be specific, I've designed a basic image map and I want the background to change based on which hotspot you're hovering over. (I'm not sure if I explained this clearly enough)
So like this.

I gave your code a try but (I'm not sure if I'm doing something wrong here) the hover didn't work except for one time and it only worked on one button and briefly.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Multiple Images in Image Map

#4 Post by _ticlock_ » Wed Jan 06, 2021 4:58 am

The example I provided should do exactly what your link shows. I copied it from my "working" screen and mainly changed image names. I will check what could be the problem when I get to my laptop.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Multiple Images in Image Map

#5 Post by _ticlock_ » Wed Jan 06, 2021 4:35 pm

I checked the code and see no problems. I made a small change to copy your example in the link (I used Solid background instead of images):

Code: Select all

screen test():
    default background_img = Solid("#a00")
    add background_img
    vbox:
        spacing 50
        button:
            add Solid("#fff", xysize = (200,50))
            hovered [SetScreenVariable("background_img", Solid("#00a")),
                With(Dissolve(0.5))]
            unhovered [SetScreenVariable("background_img", Solid("#fcc")),
                With(Dissolve(0.5))]
            action Return()
        button:
            add Solid("#fff", xysize = (200,50))
            hovered [SetScreenVariable("background_img", Solid("#cc0")),
                With(Dissolve(0.5))]
            unhovered [SetScreenVariable("background_img", Solid("#a00")),
                With(Dissolve(0.5))]
            action Return()
        button:
            add Solid("#fff", xysize = (200,50))
            hovered [SetScreenVariable("background_img", Solid("#c0c")),
                With(Dissolve(0.5))]
            unhovered [SetScreenVariable("background_img", Solid("#a00")),
                With(Dissolve(0.5))]
            action Return()
One thing, that actually can go wrong is that my code uses transition, which can potentially interfere with something else. If above does not work, try without transition:

Code: Select all

screen test():
    default background_img = Solid("#a00")
    add background_img
    vbox:
        spacing 50
        button:
            add Solid("#fff", xysize = (200,50))
            hovered SetScreenVariable("background_img", Solid("#00a"))
            unhovered SetScreenVariable("background_img", Solid("#fcc"))
            action Return()
        button:
            add Solid("#fff", xysize = (200,50))
            hovered SetScreenVariable("background_img", Solid("#cc0"))
            unhovered SetScreenVariable("background_img", Solid("#a00"))
            action Return()
        button:
            add Solid("#fff", xysize = (200,50))
            hovered SetScreenVariable("background_img", Solid("#c0c"))
            unhovered SetScreenVariable("background_img", Solid("#a00"))
            action Return()

User avatar
drbugs
Newbie
Posts: 13
Joined: Sat Nov 14, 2020 10:27 am
Contact:

Re: Multiple Images in Image Map

#6 Post by drbugs » Thu Jan 07, 2021 9:06 pm

Oh, thank you! I realised from your code that I'd edited stuff I didn't need to do, so now the image switch works! The new code also helped me with getting the image buttons rather than the text buttons.
Now I'm just having trouble getting the hotspots for the button images to work... For some reason the first button aligns perfectly but the others are way off... I'll have a play around with it. Thanks again!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], span4ev