Skip to content
TheChatArchiveThe Chat Archive
o3-mini· OpenAIHugging Face LMArena Human Preference 140K

Amazing, but it still starts flickering on the more rotated cards and the space at the…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514’s answer.
  1. User

    Amazing, but it still starts flickering on the more rotated cards and the space at the bottom of the hovered card.

  2. Assistant

    Below is one approach that helped me eliminate the flicker for rotated cards and remove the “gap” at the bottom of the hovered card. The changes include:

    1. Removing the vertical offset: Instead of moving the card upward (with a yoffset) on hover, we now simply “raise” it by scaling it up. With an anchor set to the bottom center (anchor (0.5, 1)), scaling preserves the lower edge’s position so that there’s no extra empty space or jump as the card animates.
    2. Increasing the mousearea padding: When cards are rotated and scaled up, their actual clickable area can become larger than the unrotated rectangle. By expanding the mousearea, we help prevent the hover state from “flickering” when the cursor is near a rotated edge.

    Below is the revised code. (Feel free to adjust the scale factors and padding as needed.)


    Revised Hand Screen Code

    # Player Hand
    vbox:
        align (0.5, 0.9)
        spacing 10
        fixed:
            xsize 800
            ysize 200
            pos (0.5, 0)
            anchor (0.5, 1)
            
            # Instead of re-sorting based on hover, draw the non-hovered cards first.
            $ 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
            
            # Render non-hovered cards.
            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
                    
                    button:
                        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: rotate to 0 and scale up (without any yoffset change)
                            on hover:
                                linear 0.1 rotate 0 scale 1.1
                            on idle:
                                linear 0.2 rotate base_angle scale 1.0
                        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)]
                        
                        hovered SetVariable("hovered_card_index", i)
                        unhovered SetVariable("hovered_card_index", None)
                        use card_preview(card,
                                         selected=(selected_card == i),
                                         playable=player.can_play_card(i),
                                         hoverable=(hovered_card_index == i),
                                         size=(180, 252))
            
            # Render the hovered card last (on top), if any.
            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
                
                button:
                    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 scale 1.1
                        on idle:
                            linear 0.2 rotate base_angle scale 1.0
                    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)]
                    hovered SetVariable("hovered_card_index", i)
                    unhovered SetVariable("hovered_card_index", None)
                    use card_preview(card,
                                     selected=(selected_card == i),
                                     playable=player.can_play_card(i),
                                     hoverable=(hovered_card_index == i),
                                     size=(180, 252))
    

    Revised card_preview Screen

    screen card_preview(card, selected=False, playable=False, size=(150, 210), hoverable=False, on_field=False, no_enlarge=False):
        default hover_state = [False]
        
        if on_field or no_enlarge:
            $ enlarged = None
        else:
            $ enlarged = selected or (hoverable and hover_state[0])
        
        # Decide the zoom factor without conflicting with the card button transform.
        # (Now, the card button animation takes care of scaling on hover.)
        $ zoom_factor = 1.0
        
        $ actual_size = (int(size[0] * zoom_factor), int(size[1] * zoom_factor))
        # Keeping offsets if needed; adjust if you want a custom preview offset.
        $ offset_x = 0
        $ offset_y = 0
        $ outline_thickness = max(3, int(size[0] * 0.02 * zoom_factor))
        
        $ outline_color = "#00ff00aa" if playable else ("#ffff00aa" if selected else None)
    
        fixed:
            xysize actual_size
            xoffset offset_x
            yoffset offset_y
            
            if hoverable:
                # Increase the padding to account for rotation and scaling.
                mousearea:
                    # Expand the clickable area to be more forgiving.
                    area (-20, -20, actual_size[0] + 40, actual_size[1] + 40)
                    unhovered SetDict(hover_state, 0, False)
                    hovered [SetDict(hover_state, 0, True), SetVariable("hovered_card", card)]
            
            if outline_color:
                add Solid(outline_color) xsize (actual_size[0] + outline_thickness * 2) ysize (actual_size[1] + outline_thickness * 2) xpos (-outline_thickness) ypos (-outline_thickness)
            
            # Card image (choose one based on card type).
            if on_field and isinstance(card, CreatureCard):
                add "images/[card.card_id]-creature.png" xysize actual_size
            else:
                add "images/[card.card_id].png" xysize actual_size
    
            # Mana cost (if applicable).
            if not on_field:
                fixed:
                    xpos int(size[0] * 0.02 * zoom_factor)
                    ypos int(size[0] * 0.02 * zoom_factor)
                    xsize int(size[0] * 0.25 * zoom_factor)
                    ysize int(size[0] * 0.25 * zoom_factor)
                    text "[card.mana]" size int(size[0] * 0.15 * zoom_factor) xalign 0.5 yalign 0.5 color "#FFFFFF" outlines [(int(outline_thickness/2), "#000000", 0, 0)]
    
            # Attack and Health values for CreatureCard.
            if isinstance(card, CreatureCard):
                $ attack_color = "#FFFFFF"
                if hasattr(card, "original_attack"):
                    if card.attack < card.original_attack:
                        $ attack_color = "#FF4444"
                    elif card.attack > card.original_attack:
                        $ attack_color = "#44FF44"
                
                if on_field:
                    fixed:
                        xpos int(size[0] * 0.02 * zoom_factor)
                        ypos actual_size[1] - int(size[1] * 0.25 * zoom_factor)
                        xsize int(size[0] * 0.25 * zoom_factor)
                        ysize int(size[0] * 0.25 * zoom_factor)
                        text "[card.attack]" size int(size[0] * 0.20 * zoom_factor) xalign 0.5 yalign 0.5 color attack_color outlines [(int(outline_thickness/2), "#000000", 0, 0)]
                else:
                    fixed:
                        xpos int(size[0] * 0.0 * zoom_factor)
                        ypos actual_size[1] - int(size[1] * 0.18 * zoom_factor)
                        xsize int(size[0] * 0.25 * zoom_factor)
                        ysize int(size[0] * 0.25 * zoom_factor)
                        text "[card.attack]" size int(size[0] * 0.12 * zoom_factor) xalign 0.5 yalign 0.5 color attack_color outlines [(int(outline_thickness/2), "#000000", 0, 0)]
                
                $ health_color = "#FFFFFF"
                if hasattr(card, "original_health"):
                    if card.health < card.original_health:
                        $ health_color = "#FF4444"
                    elif card.health > card.original_health:
                        $ health_color = "#44FF44"
                
                if on_field:
                    fixed:
                        xpos actual_size[0] - int(size[0] * 0.27 * zoom_factor)
                        ypos actual_size[1] - int(size[1] * 0.25 * zoom_factor)
                        xsize int(size[0] * 0.25 * zoom_factor)
                        ysize int(size[0] * 0.25 * zoom_factor)
                        text "[card.health]" size int(size[0] * 0.20 * zoom_factor) xalign 0.5 yalign 0.5 color health_color outlines [(int(outline_thickness/2), "#000000", 0, 0)]
                else:
                    fixed:
                        xpos actual_size[0] - int(size[0] * 0.21 * zoom_factor)
                        ypos actual_size[1] - int(size[1] * 0.18 * zoom_factor)
                        xsize int(size[0] * 0.25 * zoom_factor)
                        ysize int(size[0] * 0.25 * zoom_factor)
                        text "[card.health]" size int(size[0] * 0.12 * zoom_factor) xalign 0.5 yalign 0.5 color health_color outlines [(int(outline_thickness/2), "#000000", 0, 0)]
    

    Explanation of the Changes

    • Card Transform Adjustments:
      In the player's hand screen, the transform block for each button now only changes the rotation and scale when hovered. We no longer animate the vertical position or add a yoffset. This ensures that with anchor (0.5, 1), the bottom edge stays pinned to the same spot, eliminating the gap below the card.

    • Mousearea Padding:
      In the card_preview screen, the mousearea now uses a larger region (area (-20, -20, actual_size[0] + 40, actual_size[1] + 40)) so that—even if the card is rotated and scaled—the hover state isn’t lost when the pointer is near its boundaries.

    These changes should reduce flickering for the more-rotated cards and ensure that when hovered, the bottom of the card remains flush without noticeable gaps. Adjust the scale factor (here 1.1 on hover) or the mousearea’s extra padding as needed for your particular art assets and desired effect.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.