Apply a python function as transform to a whole 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
Fynmorph
Newbie
Posts: 2
Joined: Fri May 14, 2021 5:54 pm
Contact:

Apply a python function as transform to a whole button

#1 Post by Fynmorph » Fri May 14, 2021 8:22 pm

Hi, im trying to learn to use python functions as transform (im still pretty bad at it). So I wrote this MoveCursor() function and it does works on images with

Code: Select all

image img_cursor = Transform( "img_cursor_pre" , function=MoveCursor( )
but how do you apply it to a whole button? (my end goal is to have the picture change on hover)

here's my MoveCursor()

Code: Select all

    class MoveCursor(object):

        def __init__(self):
            self.xspeed = 6.0
            self.yspeed = 6.0
            self.truex = 0
            self.truey = 0
            self.moving = False

        def __call__(self, trans, st, at):
            #trans.alpha = 0
            #trans.alpha = 1
            if trans.xpos is None:
                trans.xpos = 120*id_hor + (id_ver %2 * 60) - 60
            if trans.ypos is None:
                trans.ypos = id_ver*106 - 65

            xCursor = 120*id_hor + (id_ver %2 * 60) - 60
            yCursor = id_ver*106 - 65

            dx = abs(self.truex - xCursor)
            dy = abs(self.truey - yCursor)

            if self.moving == False and (dx > 0 or dy > 0):
                self.truex = trans.xpos
                self.truey = trans.ypos
                self.moving = True
                self.xspeed = 6.0
                self.yspeed = 6.0
                if dx > dy:
                    self.yspeed *= float(dy)/float(dx)
                if dy > dx:
                    self.xspeed *= float(dx)/float(dy)

            if self.moving:
                if dx+dy > self.xspeed + self.yspeed:
                    if self.truex > xCursor + self.xspeed:
                        self.truex -= self.xspeed
                    elif self.truex < xCursor - self.xspeed:
                        self.truex += self.xspeed
                    else:
                        self.truex = xCursor

                    if self.truey > yCursor + self.yspeed:
                        self.truey -= self.yspeed
                    elif self.truey < yCursor - self.yspeed:
                        self.truey += self.yspeed
                    else:
                        self.truey = yCursor

                    trans.xpos = int( self.truex )
                    trans.ypos = int( self.truey )

                else:
                    trans.xpos = xCursor
                    trans.ypos = yCursor
                    self.moving = False

            global varhelp2
            varhelp2 = self.truey
            global varhelp3
            varhelp3 = yCursor

            return 0
            
thanks

Post Reply

Who is online

Users browsing this forum: Google [Bot], henvu50