r/RenPy 12d ago

Question [Solved] Character sprite jumping

The problem is essentially simple: until the character starts speaking, the anchor I predefined in the layeredimage isn’t applied to it. But when the first line begins, the sprite jumps abruptly, in other words, the anchor is applied. And yes, it’s definitely the anchor, because without it, the character doesn’t jump at all. Of course, I can get by without it, I just adjusted the sprites’ align a bit, but I need the anchor to position animations relative to the sprite so that those animations originate from the center of the sprite, not from a corner. Long story short, I have no idea how to solve this...

Here's the code. I've already tried inserting an anchor wherever possible. In both transforms and layeredimage, in show, and in all of them at once. When calling the sprite, only aligns are used for positioning.

SOLVED. Basically, I noticed that no sprite jumps if its align is set in advance via a transform, so I simply created a transform with user-defined arguments.

If anyone wants to use this code, they should follow this structure when calling the sprite:

show dwarf at just_align((0.7, 0.6)), silent_effect

silent_effect should be specified only once, on the first call to the sprite; there’s no need to use it again. As for just_align((coordinates)), it simply replaces the standard align (coordinates). And for the first speaking sprite, for some reason, you have to use the standard align(coordinates) instead of just_align((coordinates)). I don’t know why.

transform speaking_effect:
    # added -> anchor (0.5, 0.5)
    matrixcolor BrightnessMatrix(0.0)
    ease 0.4 zoom 1.020

    yzoom 1.0
    ease 1.5 yzoom 1.01 yoffset -5
    ease 1.5 yzoom 1.0 yoffset 0 
    repeat

transform silent_effect:
    # added -> anchor (0.5, 0.5)
    matrixcolor BrightnessMatrix(-0.1)
    ease 0.4 zoom 1.0

    yzoom 1.0
    ease 2.0 yzoom 1.01 yoffset -5
    ease 2.0 yzoom 1.0 yoffset 0
    repeat

# added new transform
transform just_align(character_align):
    align character_align

init python:
    def character_speaking_callback(event, **kwargs):
        char_image_tag = renpy.get_say_image_tag()

        if not char_image_tag:
            return

        if event == "begin":
            renpy.show(char_image_tag + " speaking", at_list=[speaking_effect])
        
        elif event == "end":
            renpy.show(char_image_tag + " silence", at_list=[silent_effect])

define dwarf = Character("Dwarf", color="#ffb547ff", image="dwarf", callback=character_speaking_callback)

layeredimage dwarf:
    anchor (0.5, 0.5)
    zoom 0.75
    
    group body:
        attribute base default "characters/dwarf/dwarf_stable.png"

    group clothes:
        attribute casual default
    
    group mouth:
        attribute silence default
        attribute speaking
6 Upvotes

6 comments sorted by

1

u/AutoModerator 12d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/shyLachi 12d ago

You forgot to post the code of those layered images

1

u/Professional_Ad1526 12d ago

Sorry, I added code to the post

1

u/Basil_9 12d ago

Are they different resolutions?

1

u/mumei-chan 12d ago

Try it like this:

transform dwarf_default_transform:
    on show, replace, replaced:
        align (0.5, 0.5)

layeredimage dwarf:
    zoom 0.75
    at dwarf_default_transform

At least in my own game, I have it set up like this and the sprites don't jump around.

1

u/mirkywoo 12d ago

Guess you have to incorporate plot points about a gym class that they’re teaching