Hide screen imagemap

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
scorlight
Regular
Posts: 67
Joined: Fri Sep 13, 2013 7:02 am
Contact:

Hide screen imagemap

#1 Post by scorlight »

Hello, I'm making a game where there is a additional object on the background and the player have to click on that object to obtain it. Kinda like a hidden object game but the sprite and the story of the game still continue normally.

Code: Select all

#This is the screen code
screen seashell:
    imagemap:
        ground "shellground.png"      #sand with no shell image
        hover "shell.png"                #shell only image
        idle "shell.png"
        #tried to add "if gotshell == False:" but no use
        hotspot (14, 641, 39, 34) clicked Replay("found", locked=False)     #use "replay" so the "return" command can return to current played game

Code: Select all

#This is the normal game
label sea:
    scene sea with dissolve
    show screen seashell               #have to use "show screen" since "call screen" will hide all the sprites and scenes
    show st happy with dissolve
    st "If you can find the magic shell, you'll get a wish"
    hide screen seashell                #tried to add "if gotshell == True:" but no use
    jump continuegame

label found:
    scene sea with dissolve
    show gotshell at center with dissolve
    "Congratulation, you got a shell!"
    hide gotshell with dissolve
    $ gotshell = True
    return
Currently, the screen will disappear once label sea ends, but I want it to disappear whenever the player picked up the shell (= label found finished). How can I do that? @@

Thank you
Artist for rent, see my art here: http://scorlight.deviantart.com/gallery/

renpic
Newbie
Posts: 19
Joined: Sat Apr 08, 2017 1:07 pm
Location: Europe
Contact:

Re: Hide screen imagemap

#2 Post by renpic »

Try to define the seashell image like this:

Code: Select all

image seashell = ConditionSwitch(
    "gotshell == True", "images/shell.png",
    "True", "images/empty.png"
)
Et voilà! :smile:

The seashell image should then work with either scene or show, and it will change as soon as your code changes the variable gotshell!

User avatar
scorlight
Regular
Posts: 67
Joined: Fri Sep 13, 2013 7:02 am
Contact:

Re: Hide screen imagemap

#3 Post by scorlight »

renpic wrote:Try to define the seashell image like this:

Code: Select all

image seashell = ConditionSwitch(
    "gotshell == True", "images/shell.png",
    "True", "images/empty.png"
)
Et voilà! :smile:

The seashell image should then work with either scene or show, and it will change as soon as your code changes the variable gotshell!
But then it's no longer an imagemap and I can't click the hotspot right? @@ I tried to add your code before the imagemap code and change it into this

Code: Select all

screen seashell:
    imagemap:
        ground seashell
        hover seashell
        hotspot (14, 641, 39, 34) clicked Replay("seafound", locked=False)
Renpy showed error said that "seashell is not defined"
Artist for rent, see my art here: http://scorlight.deviantart.com/gallery/

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: Hide screen imagemap

#4 Post by indoneko »

I think you need to direct the user interaction to the seashell screen (perhaps by using modal or other method?) at some point, otherwise the game will just ignore your screen as the player can click anywhere else to continue the game...
My avatar is courtesy of Mellanthe

renpic
Newbie
Posts: 19
Joined: Sat Apr 08, 2017 1:07 pm
Location: Europe
Contact:

Re: Hide screen imagemap

#5 Post by renpic »

scorlight wrote:
renpic wrote:Try to define the seashell image like this:

Code: Select all

image seashell = ConditionSwitch(
    "gotshell == True", "images/shell.png",
    "True", "images/empty.png"
)
Et voilà! :smile:

The seashell image should then work with either scene or show, and it will change as soon as your code changes the variable gotshell!
But then it's no longer an imagemap and I can't click the hotspot right? @@ I tried to add your code before the imagemap code and change it into this
You should be able to use it inside a imagebutton, which you can put inside a screen. Something like this:

Code: Select all

screen seashellscr:
    vbox xalign 0.5 yalign 0.3:
        if gotshell == True:
            imagebutton idle "seashell" action SetVariable("gotshell",False)
And then you just add it to your scene with:

Code: Select all

    show screen seashellscr
When you change scene, you have to remove it manually with:

Code: Select all

     hide screen seashellscr
BTW, I just noticed I put the wrong values for the "gotshell" variable, but you get the idea :) Just invert them and adjust the image definition accordingly (I suppose the natural way is to have gotshell false at the beginning, and to turn the variable to true when the player gets the shell).

You can also add a tooltip to the imagebutton (in the following example, it is contained in the images/tooltip_getshell.png file), by changing the imagebutton like this:

Code: Select all

            imagebutton idle "seashell" action [SetVariable("gotshell",False),Hide("gui_tooltip")] hovered [Show("gui_tooltip", my_picture="images/tooltip_getshell.png", my_tt_xpos=0.5, my_tt_ypos=0.4)] unhovered [Hide("gui_tooltip")]
This is the screen code to show it:

Code: Select all

screen gui_tooltip:
    add my_picture xpos my_tt_xpos ypos my_tt_ypos
EDITED to add the if inside the screen declaration, and the tooltip example.
Last edited by renpic on Sun May 07, 2017 4:34 pm, edited 1 time in total.

renpic
Newbie
Posts: 19
Joined: Sat Apr 08, 2017 1:07 pm
Location: Europe
Contact:

Re: Hide screen imagemap

#6 Post by renpic »

I supposed picking the seashell was optional in the game, but then I saw your reference to a hidden object game, so maybe you wanna wait in that scene until the player picks it. I suppose that there are easier ways to do that, but... Oh well :) This one should work too.

With the previous code, you could do that with a small loop:

Code: Select all

label shell_loop:

    e "Now you should find the shell."
    e "It is in this screen."

    if gotshell != True:
        jump shell_loop

    e "Good! You got it!"

    hide screen seashellscr
(Note that in this example, if the player clicks on the seashell during the first loop msg, the second one will still be shown to the player.)

User avatar
scorlight
Regular
Posts: 67
Joined: Fri Sep 13, 2013 7:02 am
Contact:

Re: Hide screen imagemap

#7 Post by scorlight »

indoneko wrote:I think you need to direct the user interaction to the seashell screen (perhaps by using modal or other method?) at some point, otherwise the game will just ignore your screen as the player can click anywhere else to continue the game...
That's what I want XD To let the players continue the game normally WHILE the shell lying right there in the background, available to be clicked anytime without players' awareness. Here, it's like this:
Image
renpic wrote:I supposed picking the seashell was optional in the game, but then I saw your reference to a hidden object game, so maybe you wanna wait in that scene until the player picks it. I suppose that there are easier ways to do that, but... Oh well :) This one should work too.
Omg, thank you so much for your help, that's so kind of you fren :D
Ah, it's my fault I didn't say it clear enough, like I said above to indoneko, players should be able to continue the game completely normally (unlike hidden game where people have to wait till they found all the items), the shell will just be there in the background silently and disappear after clicked or scene changed. I can use the code

Code: Select all

hide screen
to hide the shell after scene changed but to hide it whenever the player picked up the shell really is a challenge. There won't be any warning to inform that the shell is there at all, players can only know that they have to obtain a shell through the game story. So I don't think it needs loop or tooltip. But your suggestions really opened another door for me! I've stuck with imagemap, but then I searched imagebutton as well and found THIS, quite similar to what you wrote in the 2nd post.
Unfortunately, I tried various ways and still saw the error

Code: Select all

name 'gotshell' is not defined
, I tried to add the default code after the screen code (and tried to add ahead it as well) and it's still the same :( this is my code fren, Idk what's wrong with it anymore

Code: Select all

screen seashell:
    if gotshell == True:            #in the link it only wrote "if gotshell:", tried that too and the error still popped out
        imagebutton:
            idle "seashell"
            clicked [ Jump("seafound", locked = False), SetVariable("gotshell", False)]
            xpos 14 ypos 641
            xanchor 39 yanchor 34
#default gotshell == True
Last edited by scorlight on Fri May 12, 2017 6:35 am, edited 1 time in total.
Artist for rent, see my art here: http://scorlight.deviantart.com/gallery/

renpic
Newbie
Posts: 19
Joined: Sat Apr 08, 2017 1:07 pm
Location: Europe
Contact:

Re: Hide screen imagemap

#8 Post by renpic »

Ok then, let's recap it. I made some small changes so I hope this is exactly what you're looking for :)

In screens.rpy:

Code: Select all

screen seashellscr:
    vbox xalign 0.5 yalign 0.3:
        if gotshell == False:
            imagebutton idle "gui/seashell_idle.png" hover "gui/seashell_hover.png" action [SetVariable("gotshell",True),Hide("gui_tooltip"), Hide("seashellscr")] hovered [Show("gui_tooltip", my_picture="gui/tooltip_getshell.png", my_tt_xpos=0.5, my_tt_ypos=0.4)] unhovered [Hide("gui_tooltip")]                         

screen gui_tooltip:
    add my_picture xpos my_tt_xpos ypos my_tt_ypos
Of course, you need to adjust the position of the vbox according to your game. The same for the tooltip position.

The example script.rpy I used to test it:

Code: Select all

define e = Character("Eileen")

init:
    $ gotshell = False

label start:

    scene bg room

    "Hello, world."

    show screen seashellscr

    e "Now you can pick up the shell."
    e "Or you can ignore it."

    e "Ok, time to move on!"

    hide screen seashellscr
    scene black with dissolve

    "Another scene"

    e "Here you cannot pick up the shell anymore, as the seashellsrc screen was hidden."

    e "But I will give you another chance."

    scene bg room
    show screen seashellscr

    if gotshell:
        e "You cannot see the seashell anymore, as you picked it up already!"
    else:
        e "You can still see the seashell here! Last chance to pick it up!"

    hide screen seashellscr
    scene black with dissolve

    "I hope it helps! :)"

    # This ends the game.
    return
I used three images:
  • gui/seashell_hover.png
  • gui/seashell_idle.png
  • gui/tooltip_getshell.png
The tooltip image is just a nice addition, but if you don't want to use it, you can remove the code that shows it.

Another possibility would be to have a text tooltip; less work for the artists ;) Although you gotta change the screen gui_tooltip for that.
Attachments
Example tooltip image.
Example tooltip image.
tooltip_getshell.png (1.26 KiB) Viewed 2706 times

User avatar
scorlight
Regular
Posts: 67
Joined: Fri Sep 13, 2013 7:02 am
Contact:

Re: Hide screen imagemap

#9 Post by scorlight »

renpic wrote:Ok then, let's recap it. I made some small changes so I hope this is exactly what you're looking for :)
IT WORKS LIKE MAGIC!!!!!! TTTATTT) Oh thank you sooo much sweet friend!!! You really saved me there (つ´∀`)つ
Artist for rent, see my art here: http://scorlight.deviantart.com/gallery/

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot], peach_light