Skip to content

Commit b5d2db1

Browse files
committed
Expand the card hit area to solve the hover oscillation issue
1 parent f1dfa13 commit b5d2db1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

playing-cards-2-planes/Card.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ export class Card extends Container {
159159
*/
160160
enableHoverEffect() {
161161
this.on('pointerenter', () => {
162+
// Workaround for hover oscillation issue:
163+
// When a card moves on hover, the mouse pointer stays in place.
164+
// If the card moves away from the pointer, it may expose a neighbor card,
165+
// triggering that card's hover and causing the original card to "leave".
166+
// This creates an annoying oscillation between two cards.
167+
// Solution: expand the hit area on hover so the card "owns" the mouse
168+
// position even after moving, preventing the neighbor from triggering.
169+
this.hitArea = new Rectangle(
170+
-CARD_WIDTH / 2 - HOVER_DISTANCE,
171+
-CARD_HEIGHT / 2 - HOVER_DISTANCE,
172+
CARD_WIDTH + 2 * HOVER_DISTANCE,
173+
CARD_HEIGHT + 2 * HOVER_DISTANCE
174+
);
175+
162176
if (this.isParentHand()) {
163177
this.y = this.baseY - CARD_HEIGHT / 6;
164178
} else if (this.isParentLeft() || this.isParentRight()) {
@@ -167,6 +181,9 @@ export class Card extends Container {
167181
}
168182

169183
this.once('pointerleave', () => {
184+
// Restore original hit area when hover ends
185+
this.hitArea = new Rectangle(-CARD_WIDTH / 2, -CARD_HEIGHT / 2, CARD_WIDTH, CARD_HEIGHT);
186+
170187
if (this.isParentHand()) {
171188
this.y = this.baseY;
172189
} else if (this.isParentLeft() || this.isParentRight()) {

0 commit comments

Comments
 (0)