How to make characters clickable

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
Hoomst
Newbie
Posts: 10
Joined: Wed Jun 08, 2022 9:46 am
Contact:

How to make characters clickable

#1 Post by Hoomst »

In certain areas of my game I'd like to display characters that the player can talk to by clicking on them. When hovering over the character the image should get a bit brighter to indicate that it is clickable.

When first researching this, I stumbled upon someone recommending imagebuttons as character images.
While I managed to achieve what I wanted with that, there are also a few issues with that method. Like also hiding the characters when pressing the "h" key.

I then tried to use a normal image and apply a transformation on hover but that didn't do anything (it does change the image color when I delete the "on hover:").
Also I'm not sure how to make the images clickable.

Code: Select all

    
    image som = "main characters/som.png"

    transform hover:
        on hover:
            matrixcolor TintMatrix(Color(rgb=(.90,.90,1)))*BrightnessMatrix(-0.1)

    label room_som:
        scene
        show bg_room_som
        show som at hover
    
        $ renpy.pause(hard=True)
Another approach might be to display the character as an image, then putting an imagebutton of that image on top of it and transforming its opacity to 0.
While I think that this might work, i doubt its the best way to go about this.

I'm planning to have a lot of different characters in various locations so I'd prefer a method that doesn't need a lot of code per character.

I'd really appreciate your help on this one!

User avatar
Syrale
Regular
Posts: 101
Joined: Sun Oct 25, 2015 10:28 am
Completed: Robot Daycare, Deep Sea Valentine, Locke(d)
Projects: Artificial Selection, Artificial Fashionista, rei_carnation
Github: kigyo
itch: kigyo
Discord: kigyodev
Contact:

Re: How to make characters clickable

#2 Post by Syrale »

I would definitely go with imagebuttons. You can avoid the "h" hiding thing by setting the screen's layer to "master". So something like:

Code: Select all

screen characterButton(character, position):
	layer "master"
	imagebutton: 
		idle character xpos position action ...
ImageArtificial Selection (ongoing) |ImageDeep Sea Valentine | ImageRobot Daycare (NaNo19)
| ImageArtificial Fashionista (NaNo24)

My Developer Tools: Ren'Py Minimap/Location System | Ren'Py Word Counter+

Hoomst
Newbie
Posts: 10
Joined: Wed Jun 08, 2022 9:46 am
Contact:

Re: How to make characters clickable

#3 Post by Hoomst »

Thanks for the advice!
Setting the screen's layer to "master" did the job for me.

Post Reply

Who is online

Users browsing this forum: No registered users