fix: correct Go Fish card animation positioning and face-up state
- Use existing card sprites for target hand animations to prevent duplicates - Respect `handFaceUp` layout setting when flipping target cards - Calculate precise destination coordinates for drawn cards based on hand axis and index - Simplify `animateFishDraw` signature to accept explicit destination coordinates - Fix tween completion logic to properly trigger callbacks
This commit is contained in:
parent
27c13a57d4
commit
cc75ff1862
|
|
@ -746,9 +746,12 @@ export default class GoFishGame extends Phaser.Scene {
|
|||
: targetShow.x + (i - (n - 1) / 2) * (CARD_W + 8);
|
||||
const ty = isTargetVert ? targetShow.y + (i - (n - 1) / 2) * (CARD_H + 8)
|
||||
: targetShow.y;
|
||||
const sprite = this.makeCardSprite(card, targetLayout.handCenter.x, targetLayout.handCenter.y, {
|
||||
faceUp: false, rotation: 0,
|
||||
});
|
||||
const existingTargetSprite = this.cardObjs.get(`hand-${targetSeat}-${card.id}`);
|
||||
const sprite = existingTargetSprite
|
||||
?? this.makeCardSprite(card, targetLayout.handCenter.x, targetLayout.handCenter.y, {
|
||||
faceUp: targetLayout.handFaceUp, rotation: 0,
|
||||
});
|
||||
if (existingTargetSprite) this.cardObjs.delete(`hand-${targetSeat}-${card.id}`);
|
||||
sprite.setDepth(D.banner - 4);
|
||||
this.transientObjs.push(sprite);
|
||||
this.tweens.add({
|
||||
|
|
@ -757,7 +760,9 @@ export default class GoFishGame extends Phaser.Scene {
|
|||
duration: 250,
|
||||
delay: i * 80,
|
||||
ease: 'Cubic.easeOut',
|
||||
onComplete: () => this.flipCardFaceUp(sprite, card),
|
||||
onComplete: () => {
|
||||
if (!targetLayout.handFaceUp) this.flipCardFaceUp(sprite, card);
|
||||
},
|
||||
});
|
||||
return { sprite, tx, ty };
|
||||
});
|
||||
|
|
@ -1019,27 +1024,37 @@ export default class GoFishGame extends Phaser.Scene {
|
|||
|
||||
if (sprite) {
|
||||
const revealCard = askerSeat === 0 ? after.lastAsk.drawnCard : null;
|
||||
this.animateFishDraw(sprite, askerSeat, revealCard, continueAfterDraw);
|
||||
const drawnCard = after.lastAsk.drawnCard;
|
||||
const newHand = after.players[askerSeat].hand;
|
||||
const cardIndex = newHand.findIndex(c => c.id === drawnCard.id);
|
||||
const askerLayout = slotLayout(this.slotForSeat[askerSeat]);
|
||||
let destX, destY;
|
||||
if (askerLayout.handAxis === 'x') {
|
||||
destX = askerLayout.handCenter.x + (cardIndex - (newHand.length - 1) / 2) * HAND_SPREAD;
|
||||
destY = askerLayout.handCenter.y;
|
||||
} else {
|
||||
destX = askerLayout.handCenter.x;
|
||||
destY = askerLayout.handCenter.y + (cardIndex - (newHand.length - 1) / 2) * HAND_SPREAD;
|
||||
}
|
||||
this.animateFishDraw(sprite, revealCard, destX, destY, continueAfterDraw);
|
||||
} else {
|
||||
this.time.delayedCall(50, continueAfterDraw);
|
||||
}
|
||||
}
|
||||
|
||||
animateFishDraw(sprite, askerSeat, revealCard, onComplete) {
|
||||
const layout = slotLayout(this.slotForSeat[askerSeat]);
|
||||
animateFishDraw(sprite, revealCard, destX, destY, onComplete) {
|
||||
sprite.setDepth(D.banner - 4);
|
||||
this.transientObjs.push(sprite);
|
||||
|
||||
const flyToHand = () => {
|
||||
this.tweens.add({
|
||||
targets: sprite,
|
||||
x: layout.handCenter.x, y: layout.handCenter.y,
|
||||
x: destX, y: destY,
|
||||
rotation: 0,
|
||||
alpha: 0,
|
||||
duration: 400,
|
||||
ease: 'Cubic.easeIn',
|
||||
onComplete: () => { if (sprite.active) sprite.destroy(); },
|
||||
onComplete: () => onComplete(),
|
||||
});
|
||||
this.time.delayedCall(450, onComplete);
|
||||
};
|
||||
|
||||
if (revealCard) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue