How do I fix this menu level swipe that I made?

wongselentwongselent Posts: 4Member
edited April 7 in GUI

I'm making a menu level swipe, but there is a problem when shifting the card, the card seems to vibrate. is there something wrong with the code i made ?,
But when the card is set pivot_offset to a value of 0, the card becomes normal.
Thank you for your help

extends ScrollContainer


onready var margin_container: MarginContainer = $CenterContainer/MarginContainer
onready var card_node_list: Array = $CenterContainer/MarginContainer/HBoxContainer.get_children()

func _process(delta: float) -> void:
    var _center_pos: Vector2 = (rect_size / 2)
    for _card in card_node_list:
        var _card_pos = _card.rect_global_position.x
        if _card_pos > (_center_pos.x - 100) and _card_pos < (_center_pos.x + 100):
            _card.rect_scale = lerp(_card.rect_scale, Vector2(1, 1), 0.1)
        else:
            _card.rect_scale = lerp(_card.rect_scale, Vector2(0.7, 0.7), 0.1)




Tags :

Best Answer

  • GlyphTheWolfGlyphTheWolf Posts: 78
    Accepted Answer

    Hi,

    My guess is that when you use _card.rect_global_position.x that also takes into account scale of object.

    Now since you scale your cards with origin at center I suppose it may happen that because of scale change.

    Lets suppose you move your card from the center to the left side. At the center it is big, when position.x go "outside of if bounds" it is getting smaller. When getting smaller position.x is actually going back to the center (because you scale with card center as origin) and it again meets "if bounds" so it is getting bigger and everything is happening all the time the same way until you move your card far enaugh from your threashold position.

Answers

  • GlyphTheWolfGlyphTheWolf Posts: 78Member
    Accepted Answer

    Hi,

    My guess is that when you use _card.rect_global_position.x that also takes into account scale of object.

    Now since you scale your cards with origin at center I suppose it may happen that because of scale change.

    Lets suppose you move your card from the center to the left side. At the center it is big, when position.x go "outside of if bounds" it is getting smaller. When getting smaller position.x is actually going back to the center (because you scale with card center as origin) and it again meets "if bounds" so it is getting bigger and everything is happening all the time the same way until you move your card far enaugh from your threashold position.

  • wongselentwongselent Posts: 4Member

    Thank you for your help, now I can make it look better =)

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file