Imagebutton that moves other imagebuttons on hover[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
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Imagebutton that moves other imagebuttons on hover[SOLVED]

#1 Post by TellerFarsight »

So I have a screen with two imagebuttons on it, and I want to make it so that hovering on one button moves the *other* button out of the way.

I know how to have it show new images and screens and I know how to apply transforms on a button itself, but what I'm trying to figure out is how to get one button to affect another button, both of which are already displayed on the screen.

My current plan is to try and use the SetVariable function, to have each button come with an if/elif statement to describe their actions on idle, and have the on hover action of the other button be to change the variable and set a new idle action. I don't know if that makes any sense, but I'll probably try it in the morning. If someone has an easier solution to this, it would probably save me some insanity.
Last edited by TellerFarsight on Thu Aug 24, 2017 10:24 pm, edited 1 time in total.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Imagebutton that moves other imagebuttons on hover

#2 Post by Scribbles »

maybe....

Code: Select all

if not button01:
    imagebutton ## your image button  02 code
if not button 02:
    imagebutton ## your image button 01 code
then... set the button01/button02 to True or False... within your function? The button01/02 would have to be set to False so that they both show at first, and then set to true when clicked, and then back to False when you wanted them both to show up again

i'm NOT sure this would work, or if it's even what you want...... but i hope it helps
Image - Image -Image

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Imagebutton that moves other imagebuttons on hover

#3 Post by Alex »

If you could draw some images that would show how your want all this to act... this might help to find the solution.

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Imagebutton that moves other imagebuttons on hover

#4 Post by TellerFarsight »

Hopefully this gets the idea across. The sizes of the pictures ended up different but the only movement I'm talking about is indicated by the arrows. Otherwise they should stay still.
Attachments
1.png
1.png (3.83 KiB) Viewed 1587 times
2.png
2.png (4.55 KiB) Viewed 1587 times
3.png
3.png (3.62 KiB) Viewed 1587 times
4.png
4.png (4.86 KiB) Viewed 1587 times
5.png
5.png (3.44 KiB) Viewed 1587 times
6.png
6.png (4.72 KiB) Viewed 1587 times
7.png
7.png (3.44 KiB) Viewed 1587 times
8.png
8.png (4.69 KiB) Viewed 1587 times
9.png
9.png (3.43 KiB) Viewed 1587 times
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Imagebutton that moves other imagebuttons on hover

#5 Post by Alex »

Well, its not code wise, but could be used as a workaround...

Code: Select all

default b_offset = 0
default b_max_offset = -50
default b_step_time = 0.1
default b_step = 10

screen test_scr():
    default my_move = False
    textbutton "Test!" action [[]] align(0.2, 0.2) xoffset b_offset
    textbutton "Hover me!" action [[]] hovered SetScreenVariable("my_move", True) unhovered SetScreenVariable("my_move", False) align(0.8, 0.2)
    
    if my_move:
        if b_offset > b_max_offset:
            timer b_step_time action SetVariable("b_offset", b_offset-b_step) repeat True
    else:
        if b_offset < 0:
            timer b_step_time action SetVariable("b_offset", b_offset+b_step) repeat True

# The game starts here.
label start:
    "..."
    show screen test_scr
    "?"

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Imagebutton that moves other imagebuttons on hover

#6 Post by TellerFarsight »

Oh wow! Thanks Alex. I had gotten around to setting up with SetVariable and offsets but that would just make it jump. Actually creating the crawl like that is very clever.

I don't really know how to get a video of it, but I'll post some pictures of the thing I'm using this for, and you'll be able to imagine.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Imagebutton that moves other imagebuttons on hover

#7 Post by TellerFarsight »

Took me a little while to adjust some things and get it implemented, but it ended up working great!
Attachments
menu1.png
menu2.png
menu3.png
menu4.png
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Imagebutton that moves other imagebuttons on hover

#8 Post by TellerFarsight »

Alright so I'm having some trouble with this again. I want to do a similar thing and I've been trying to use this framework to do it.
I'm trying to make a button, whose action is make a button or image move in a direction and then come back (changes offset incrementally to like 20, then turn around and come back to 0). I'm also doing this in a bit of code that includes python objects, so I've been trying to do those both with renpy and with python functions, and I can't get either to work.
Here's the code I have right now and it doesn't work. Hitting "Attack" makes the squares slide to the left and then stop, and nothing brings them back to 0.

Code: Select all

init -1 python:
    from random import randint
    class Unit(object):
        def __init__(self,name,hp,attack,defense):
            self.name = name
            self.hp = hp
            self.attack = attack
            self.defense = defense
        def damage(self, enemy):
            damage = randint(1,self.attack) - enemy.defense  ## I wonder if you could have this function
            if damage >=0:				  ## or another function move the squares
                enemy.hp = enemy.hp - damage
            
        
default Marl = Unit("Marl",100,20,1)
default Gorb = Unit("Gorb",100,10,2)
default gloop = 0
default movelymove = False

screen dudes():
    style_prefix "dudely"
    text "[gloop]"
    textbutton "Attack!" yalign 0.5 xanchor 0.5 xpos 100 action (Function(Marl.damage,Gorb), SetVariable("movelymove",True))
    textbutton "Attack!" yalign 0.5 xanchor 0.5 xpos 700 action (Function(Gorb.damage,Marl), SetVariable("movelymove",True))
    button:
        xoffset gloop
        add Solid("ff0000") size (50,50)
        text "[Marl.hp]" yanchor 0.5 ypos 25 xanchor 0.5 xpos 25
        xpos 200
    button:
        xoffset gloop
        add Solid("0000ff") size (50,50)
        text "[Gorb.hp]" yanchor 0.5 ypos 25 xanchor 0.5 xpos 25
        xpos 600
    if movelymove:							 ## The indentations here are something I was trying to play around with, changing if and 
        if gloop > -20:							 ## elif and else. On a side note, it gave me an invalid syntax error whenever I type 
            timer .01 action SetVariable("gloop", gloop-5) repeat True 	 ## something like "elif gloop = -20" where the "else" is.
        else:
            action SetVariable("movelymove", False)
    elif gloop < 0:
        timer .01 action SetVariable("gloop", gloop+5) repeat True
    
style dudely_button:
    xanchor 25
    yalign 0.5
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

Post Reply

Who is online

Users browsing this forum: No registered users