fix(CATS) 修复角色动画与原点问题

This commit is contained in:
chicrobot committed 2026-02-03 13:46:41 +08:00
1 parent f6f7076fcb
commit 683803945a
2 files changed
+45 -24

No files matched your search

@@ -109,14 +109,8 @@ export default class CharacterAnimationTestScene extends Phaser.Scene {
this.anims.create({
key: 'player0-move',
frames: [
{ key: 'player0-0' },
{ key: 'player0-1' },
{ key: 'player0-2' },
{ key: 'player0-3' },
{ key: 'player0-4' },
{ key: 'player0-5' },
{ key: 'player0-6' },
{ key: 'player0-7' }
{ key: 'player0-2' }
],
frameRate: 10,
repeat: -1
@@ -126,14 +120,8 @@ export default class CharacterAnimationTestScene extends Phaser.Scene {
this.anims.create({
key: 'player1-move',
frames: [
{ key: 'player1-0' },
{ key: 'player1-1' },
{ key: 'player1-2' },
{ key: 'player1-3' },
{ key: 'player1-4' },
{ key: 'player1-5' },
{ key: 'player1-6' },
{ key: 'player1-7' }
{ key: 'player1-2' }
],
frameRate: 10,
repeat: -1
@@ -218,14 +206,29 @@ export default class CharacterAnimationTestScene extends Phaser.Scene {
* 切换角色
*/
switchCharacter() {
// 根据当前使用的纹理切换角色
if (this.player.anims.currentAnim && this.player.anims.currentAnim.key === 'player0-move') {
// 检查单位是否在移动
const isMoving = Math.abs(this.player.body.velocity.x) > 10 || Math.abs(this.player.body.velocity.y) > 10;
// 切换角色
if (this.currentCharacterText.text === '当前角色: Player0') {
// 切换到Player1
this.player.play('player1-move');
this.currentCharacterText.setText('当前角色: Player1');
if (isMoving) {
this.player.play('player1-move');
} else {
this.player.anims.stop();
this.player.setTexture('player1-0');
}
console.log('切换到Player1');
} else {
// 切换到Player0
this.player.play('player0-move');
this.currentCharacterText.setText('当前角色: Player0');
if (isMoving) {
this.player.play('player0-move');
} else {
this.player.anims.stop();
this.player.setTexture('player0-0');
}
console.log('切换到Player0');
}
}
@@ -307,9 +310,8 @@ export default class CharacterAnimationTestScene extends Phaser.Scene {
unit.setFlipX(false); // 向右不翻转
}
// 播放动画
if (!unit.anims.isPlaying) {
// 根据当前角色播放对应的移动动画
// 播放移动动画
if (!unit.anims.isPlaying || !unit.anims.currentAnim.key.includes('move')) {
if (this.currentCharacterText.text === '当前角色: Player0') {
unit.play('player0-move');
} else {
@@ -317,8 +319,13 @@ export default class CharacterAnimationTestScene extends Phaser.Scene {
}
}
} else {
// 停止动画,保持当前帧
unit.anims.pause();
// 静止状态,显示图片0
unit.anims.stop();
if (this.currentCharacterText.text === '当前角色: Player0') {
unit.setTexture('player0-0');
} else {
unit.setTexture('player1-0');
}
}
}
}