Page 1 of 1
[SOLVED!] Moving an image by pressing a button?
Posted: Fri Apr 01, 2022 10:40 am
by Michael Regal
Okay, this might be a bit of an ask here, but is it in any way possible for me to make a function that will move the image on the left to the X on the right with "linear" animation when clicking on the X on the right?

Re: Moving an image by pressing a button?
Posted: Fri Apr 01, 2022 10:51 am
by rayminator
it is possible to do this I think you need something from pygame coding to do this it out of my knowledge but I believe there something in the codebook section for this
Re: Moving an image by pressing a button?
Posted: Fri Apr 01, 2022 11:03 am
by Michael Regal
A kind soul on the Renpy discord gave me the solution! Thanks guys!
Code: Select all
transform move_to_right:
on show:
linear 1.0 xoffset 200 #aka the new position
screen yourscreen:
default move_me = False
showif move_me:
add 'abstract' at move_to_right
else:
add 'abstract'
textbutton "A button":
action SetScreenVariable('move_me', True)
Re: Moving an image by pressing a button?
Posted: Fri Apr 01, 2022 11:11 am
by Ocelot
An example:
Code: Select all
image cross = Crop((0, 0, 30, 30), Solid("#F00"))
image marker = Crop((0, 0, 20, 50), Solid("#0F0"))
default marker_pos = (0.1, 0.5)
screen move_example():
imagebutton:
idle "cross"
action SetVariable("marker_pos", (0.1, 0.5))
pos (0.1, 0.5)
anchor (0.5, 0.5)
imagebutton:
idle "cross"
action SetVariable("marker_pos", (0.4, 0.5))
pos (0.4, 0.5)
anchor (0.5, 0.5)
add "marker":
anchor (0.5, 1.0)
at marker_move(marker_pos)
transform marker_move(position, duration=0.8):
linear duration pos position
label start:
show screen move_example
' . . . '
return
https://i.imgur.com/dwUKvPl.gif
EDIT: Oh... I glad you found a solution.
Re: Moving an image by pressing a button?
Posted: Fri Apr 01, 2022 11:47 am
by Michael Regal
Ocelot wrote: ↑Fri Apr 01, 2022 11:11 am
An example:
Code: Select all
image cross = Crop((0, 0, 30, 30), Solid("#F00"))
image marker = Crop((0, 0, 20, 50), Solid("#0F0"))
default marker_pos = (0.1, 0.5)
screen move_example():
imagebutton:
idle "cross"
action SetVariable("marker_pos", (0.1, 0.5))
pos (0.1, 0.5)
anchor (0.5, 0.5)
imagebutton:
idle "cross"
action SetVariable("marker_pos", (0.4, 0.5))
pos (0.4, 0.5)
anchor (0.5, 0.5)
add "marker":
anchor (0.5, 1.0)
at marker_move(marker_pos)
transform marker_move(position, duration=0.8):
linear duration pos position
label start:
show screen move_example
' . . . '
return
https://i.imgur.com/dwUKvPl.gif
EDIT: Oh... I glad you found a solution.
Your code is MUCH more efficient though