Shake not working

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
neometalero
Regular
Posts: 198
Joined: Sun Oct 23, 2016 3:51 am
Completed: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Projects: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Deviantart: neometalero
Contact:

Shake not working

#1 Post by neometalero »

Im using the shake from the cookbook https://www.renpy.org/wiki/renpy/doc/co ... ke_effect
and Im getting this error
Image
It's an old project so I dont feel like creating a new transformation and apply it in all cases. Any way to salvage this old code?
Working on many weird narrative games at Curse Box Studios
Image
https://www.curseboxstudios.com/

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

Re: Shake not working

#2 Post by Alex »

neometalero wrote: Sat Apr 13, 2024 7:18 pm ...It's an old project so I dont feel like creating a new transformation and apply it in all cases. Any way to salvage this old code?
Not tested, but try to convert the result of calculation to integer, like

Code: Select all

nx = xpos + int(self.dist * (renpy.random.random() * 2 - 1))

User avatar
neometalero
Regular
Posts: 198
Joined: Sun Oct 23, 2016 3:51 am
Completed: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Projects: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Deviantart: neometalero
Contact:

Re: Shake not working

#3 Post by neometalero »

Alex wrote: Sun Apr 14, 2024 5:03 am
neometalero wrote: Sat Apr 13, 2024 7:18 pm ...It's an old project so I dont feel like creating a new transformation and apply it in all cases. Any way to salvage this old code?
Not tested, but try to convert the result of calculation to integer, like

Code: Select all

nx = xpos + int(self.dist * (renpy.random.random() * 2 - 1))
I got the same error doing that. Is looking for a position type not an int
Working on many weird narrative games at Curse Box Studios
Image
https://www.curseboxstudios.com/

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

Re: Shake not working

#4 Post by Alex »

neometalero wrote: Sun Apr 14, 2024 7:11 pm ...
Hm, just tested and the original code worked for me in 8.1.0.
What version of Ren'Py do you use? Could you provide the part of the code where you using this shake effect?

Upd: original code worked in 8.2.1 (no errors).

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

Re: Shake not working

#5 Post by Alex »

neometalero wrote: Sun Apr 14, 2024 7:11 pm ...I got the same error doing that. Is looking for a position type not an int
Upd: this should work...

Code: Select all

init:
    python:
        import math

        class Shaker(object):

            anchors = {
                'top' : 0.0,
                'center' : 0.5,
                'bottom' : 1.0,
                'left' : 0.0,
                'right' : 1.0,
                }

            def __init__(self, start, child, dist):
                if start is None:
                    start = child.get_placement()
                #
                self.start = [ self.anchors.get(i, i) for i in start ]  # central position
                self.dist = dist    # maximum distance, in pixels, from the starting point
                self.child = child

            def __call__(self, t, sizes):
                # Float to integer... turns floating point numbers to
                # integers.
                def fti(x, r):
                    if x is None:
                        x = 0
                    if isinstance(x, float):
                        return int(x * r)
                    elif isinstance(x, position): # <-- position type
                        return int(x.relative * r + x.absolute)
                    else:       
                        return x

                xpos, ypos, xanchor, yanchor = [ fti(a, b) for a, b in zip(self.start, sizes) ]

                xpos = xpos - xanchor
                ypos = ypos - yanchor
                
                nx = xpos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
                ny = ypos + (1.0-t) * self.dist * (renpy.random.random()*2-1)

                return (int(nx), int(ny), 0, 0)
                

        def _Shake(start, time, child=None, dist=100.0, **properties):

            move = Shaker(start, child, dist=dist)

            return renpy.display.layout.Motion(move,
                          time,
                          child,
                          add_sizes=True,
                          **properties)

        Shake = renpy.curry(_Shake)
    #

#


image test_img:
    Solid("#ccc")
    xysize(100, 100)

image test_img_2:
    Solid("#c00")
    xysize(100, 100)

transform test_pos_tr():
    #anchor (50, 50)
    #ypos position (0, 0.50)
    #xpos position (0, 0.50)
    #align(0.5, 0.5)
    #pos(int(config.screen_width*0.5), int(config.screen_height*0.5))
    pos(0.5, 0.5)
    #pos(960, 540)
    anchor (0.5, 0.5)
    

label start:
    "..."
    show test_img_2 at truecenter
    show test_img at test_pos_tr
    "... ..."
    show test_img at test_pos_tr, Shake(None, 1.5, dist=70) # None to use current position
    "?!"

Post Reply

Who is online

Users browsing this forum: No registered users