[SOLVED!] Moving an image by pressing a button?

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
Michael Regal
Newbie
Posts: 11
Joined: Fri Mar 25, 2022 11:38 pm
Contact:

[SOLVED!] Moving an image by pressing a button?

#1 Post by Michael Regal » Fri Apr 01, 2022 10:40 am

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?

Image
Last edited by Michael Regal on Fri Apr 01, 2022 11:03 am, edited 1 time in total.

rayminator
Miko-Class Veteran
Posts: 754
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Moving an image by pressing a button?

#2 Post by rayminator » Fri Apr 01, 2022 10:51 am

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

Michael Regal
Newbie
Posts: 11
Joined: Fri Mar 25, 2022 11:38 pm
Contact:

Re: Moving an image by pressing a button?

#3 Post by Michael Regal » Fri Apr 01, 2022 11:03 am

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)

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Moving an image by pressing a button?

#4 Post by Ocelot » 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.
< < insert Rick Cook quote here > >

Michael Regal
Newbie
Posts: 11
Joined: Fri Mar 25, 2022 11:38 pm
Contact:

Re: Moving an image by pressing a button?

#5 Post by Michael Regal » Fri Apr 01, 2022 11:47 am

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

Post Reply

Who is online

Users browsing this forum: Alex, nyeowmi