Godot Version
4.2.2
Question
I’m making a card game where I have a hand of cards at the bottom of the screen (like Balatro, Slay the Spire, etc.). When you mouse over a card it gets bigger and displays in front of the other cards (I reorder the children of the hand node so that the selected card is on top). Then when the mouse exits the card it pops back down the cards are reordered. I’m doing this with Controls using the mouse_entered/mouse_exited signals.
When the mouse moves too quickly, it doesn’t register the mouse exiting the card or entering another which makes sense as it would only be checking that at a fixed rate. BUT, this only happens when the mouse moves left not when it moves right:
Code Below:
select_card is connected to the mouse_entered signal and reset card to the mouse_exited signal
func select_card():
z_index += 1
get_parent().move_child(self, -1)
if tween_hover and tween_hover.is_running():
tween_hover.kill()
tween_hover = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_ELASTIC)
tween_hover.tween_property(self, "scale", Vector2(1.5, 1.5), 0.5)
func reset_card():
z_index = 0
if get_parent() is Hand:
reorder_cards()
# Reset rotation
if !get_tree():
return
if tween_rot and tween_rot.is_running():
tween_rot.kill()
tween_rot = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK).set_parallel(true)
tween_rot.tween_property(card_viewport_texture.material, "shader_parameter/x_rot", 0.0, 0.5)
tween_rot.tween_property(card_viewport_texture.material, "shader_parameter/y_rot", 0.0, 0.5)
# Reset scale
if tween_hover and tween_hover.is_running():
tween_hover.kill()
tween_hover = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_ELASTIC)
tween_hover.tween_property(self, "scale", Vector2.ONE, 0.55)
func reorder_cards():
var cards = get_parent().get_children()
cards.sort_custom(
func(a,b) : return a.position.x > b.position.x
)
for card in cards:
get_parent().move_child(card, 0)
Any ideas would be appreciated!