[solved?]How to make image 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
User avatar
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

[solved?]How to make image clickable?

#1 Post by SONTSE » Sun May 04, 2014 9:36 pm

let's say i have an image

Code: Select all

image smile = "smile.png"
and display it on certain location

Code: Select all

    show smile xpos 300 
and then i need to make some manipulations on it
eg. to move it:

Code: Select all

    show smile:
        ease 1 xpos 600

and this event should happen when i click on the assumed image
this clickable option should maintain during the scene
for my case it hasn't to be exactly image to be clicked, it can be eg. some invisible area above it.

any simple solutions?
if it takes some complicated things like screens or sprites i'm afraid i need some example that performs really close to my needs, so i can adapt it.
Last edited by SONTSE on Sun May 04, 2014 11:31 pm, edited 1 time in total.

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: How to make image clickable?

#2 Post by Asceai » Sun May 04, 2014 10:02 pm

This actually isn't necessarily that easy to do, or at least, if it is, I don't know of an easy way to do it. I also don't know if you want the image to be clickable again and again.

This is, however, what you asked for, so good luck:

Code: Select all

label start:
    image smile = "smile.png"
    transform smile_action:
      ease 1 yoffset -100
    show expression renpy.display.behavior.ImageButton("smile", "smile", clicked=[renpy.curry(renpy.show)("smile", what=At("smile", smile_action)), renpy.restart_interaction], focus_mask=True) at truecenter as smile
    "You've created a new Ren'Py game."

    "Once you add a story, pictures, and music, you can release it to the world!"

    return
I'm sure a less horrifying solution would be appreciated, if anyone has one. Screens are generally the best way to do anything that requires clicking, so avoiding them requires some contortions.

User avatar
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

Re: How to make image clickable?

#3 Post by SONTSE » Sun May 04, 2014 11:29 pm

It works like a charm(for my case)!
Thank you a lot, Asceai!
I'm overwhelmed with joy and amazed of beauty and elegance of your script (compared to mine ^^'''''' )

so i wonder should i call it solved? i mean it satisfies my case, in which the image should perform transition as reaction to click exactly once, but, maybe, there will be more solutions for someone with more complicated yet relevant cases.

Post Reply

Who is online

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