The flickering is happening because the rotated cards create gaps and irregular hit areas, and the mousearea doesn't account for the card's rotation. Here's a solution that fixes both issues:
renpy
# Player Hand
vbox:
align (0.5, 0.9)
spacing 10
fixed:
xsize 800
ysize 200
pos (0.5, 0)
anchor (0.5, 1)
$ card_count = len(player.hand)
$ center_position = (card_count - 1) / 2.0
$ max_height_adjustment = min(20, 5 + card_count * 6) if card_count > 1 else 0
# Create a larger mousearea overlay for each card to handle hover detection
for i, card in enumerate(player.hand):
$ base_angle = -20 + (40.0 / max(1, card_count - 1)) * i if card_count > 1 else 0
$ base_xpos = 250 - (card_count * 30) + (i * 120) if card_count > 1 else 250
if card_count <= 1:
$ height_adjustment = 0
else:
$ normalized_pos = (i - center_position) / max(1, center_position)
$ height_adjustment = int(max_height_adjustment * (1 - (normalized_pos ** 4)))
$ base_ypos = 150 - height_adjustment
# Invisible hover detection area - larger and positioned to cover rotated card
button:
id "hover_area_{i}"
xsize 220 # Wider than card to account for rotation
ysize 280 # Taller to cover the full rotated area
pos (base_xpos, base_ypos - 20) # Slightly higher to cover gaps
anchor (0.5, 1)
background None
hovered SetVariable("hovered_card_index", i)
unhovered SetVariable("hovered_card_index", None)
# Make the action work on the hover area too
if selected_card == i:
action [SetVariable("active_targeting_session", None), SetVariable("selected_card", None)]
else:
action [SetVariable("selected_card", i), Function(player.initiate_play_card, i), SetVariable("selected_creature", None)]
# Render non-hovered cards first
for i, card in enumerate(player.hand):
if i != hovered_card_index:
$ base_angle = -20 + (40.0 / max(1, card_count - 1)) * i if card_count > 1 else 0
$ base_xpos = 250 - (card_count * 30) + (i * 120) if card_count > 1 else 250
if card_count <= 1:
$ height_adjustment = 0
else:
$ normalized_pos = (i - center_position) / max(1, center_position)
$ height_adjustment = int(max_height_adjustment * (1 - (normalized_pos ** 4)))
$ base_ypos = 150 - height_adjustment
fixed:
id "player_hand_card_{i}"
xsize 180
ysize 252
pos (base_xpos, base_ypos)
anchor (0.5, 1)
at transform:
rotate base_angle
transform_anchor True
on hover:
linear 0.1 rotate 0
linear 0.1 ypos 150
linear 0.1 yoffset -30
on idle:
linear 0.2 rotate base_angle
linear 0.2 ypos base_ypos
linear 0.2 yoffset 0
use card_preview(card, selected=(selected_card == i), playable=player.can_play_card(i), hoverable=False, size=(180, 252))
# Render hovered card last (on top)
if hovered_card_index is not None and hovered_card_index < len(player.hand):
$ i = hovered_card_index
$ card = player.hand[i]
$ base_angle = -20 + (40.0 / max(1, card_count - 1)) * i if card_count > 1 else 0
$ base_xpos = 250 - (card_count * 30) + (i * 120) if card_count > 1 else 250
if card_count <= 1:
$ height_adjustment = 0
else:
$ normalized_pos = (i - center_position) / max(1, center_position)
$ height_adjustment = int(max_height_adjustment * (1 - (normalized_pos ** 4)))
$ base_ypos = 150 - height_adjustment
fixed:
id "player_hand_card_{i}_hovered"
xsize 180
ysize 252
pos (base_xpos, base_ypos)
anchor (0.5, 1)
at transform:
rotate base_angle
transform_anchor True
on hover:
linear 0.1 rotate 0
linear 0.1 ypos 150
linear 0.1 yoffset -30
on idle:
linear 0.2 rotate base_angle
linear 0.2 ypos base_ypos
linear 0.2 yoffset 0
use card_preview(card, selected=(selected_card == i), playable=player.can_play_card(i), hoverable=True, size=(180, 252))
And update the card_preview screen to remove the internal mousearea since we're handling hover detection externally:
renpy
Key changes:
Separate hover detection: Created invisible button overlays that are larger and positioned to cover the full area where rotated cards might be, including gaps between cards.
Removed internal mousearea: The card preview no longer handles its own hover detection, eliminating conflicts between multiple hover areas.
Larger hit areas: The hover detection areas are 220x280 pixels instead of 180x252, and positioned slightly higher to cover gaps created by rotation.
Simplified hover logic: The card preview now simply uses the hoverable parameter directly instead of managing internal hover state.
This approach ensures smooth hover detection across the entire card area, including rotated cards and the spaces between them, while maintaining stable positioning and eliminating flickering.