Resize while keeping the same position for a border

Godot Version

Stable 4.2

Question

Hi! I have the following code wich intended behavior is to scale down the top sprite while keeping the bottom border at the same level (as if it was water draining)

    for i in $"..".get_children():
        var new_position = initial_position + sprite.texture.get_height() + initial_height
        sprite.position.y = new_position
        var tween = get_tree().create_tween().set_parallel(true)
        tween.tween_property(i, "scale", Vector2(1, 0), 3)
    if sprite.scale.y <= 0:
        drain = false
        $"..".queue_free()`

Actual behavior:

However i can’t find a formula to calculate this correctly, Thank you for your time !

The scale affects both sides, moving them towards the center of the sprite. Try moving the sprite down at half the rate of the scale, it seems like you have the variables defined. If this doesn’t work I would double check initial_position and initital_height and/or show where those are defined.

for i in $"..".get_children():
    var new_position = initial_position + initial_height/2
    var tween = get_tree().create_tween().set_parallel(true)
    tween.tween_property(i, "scale", Vector2(1, 0), 3)
    tween.tween_property(i, "position", new_position, 3)
1 Like

I fixed it by lowering the center but i think you are right for what i was asking, i’ll eventually get back here for a better solution