|
@@ -357,7 +357,8 @@ class GameScene extends Phaser.Scene {
|
|
|
|
|
|
createPlayer() {
|
|
|
// 创建玩家
|
|
|
- this.player = this.physics.add.sprite(GAME_WIDTH / 2, GAME_HEIGHT - 100, 'playerAnim');
|
|
|
+ //this.player = this.physics.add.sprite(GAME_WIDTH / 2, GAME_HEIGHT - 100, 'playerAnim');
|
|
|
+ this.player = this.physics.add.sprite(direction.value, GAME_HEIGHT - 100, 'playerAnim');
|
|
|
this.player.setCollideWorldBounds(true);
|
|
|
this.player.setScale(0.8);
|
|
|
this.player.lives = this.lives;
|
|
@@ -914,12 +915,14 @@ class GameScene extends Phaser.Scene {
|
|
|
// 玩家移动逻辑(原有代码保持不变)
|
|
|
if (this.player && this.player.active) {
|
|
|
if (this.cursors.left.isDown) {
|
|
|
- this.player.setVelocityX(-200);
|
|
|
+ //this.player.setVelocityX(-200);
|
|
|
+ this.player.setX(direction.value);
|
|
|
if (this.player.anims.currentAnim?.key !== 'playerLeft' && !this.player.anims.paused) {
|
|
|
this.player.anims.play('playerLeft', true);
|
|
|
}
|
|
|
} else if (this.cursors.right.isDown) {
|
|
|
- this.player.setVelocityX(200);
|
|
|
+ //this.player.setVelocityX(200);
|
|
|
+ this.player.setX(direction.value);
|
|
|
if (this.player.anims.currentAnim?.key !== 'playerRight' && !this.player.anims.paused) {
|
|
|
this.player.anims.play('playerRight', true);
|
|
|
}
|
|
@@ -1104,11 +1107,16 @@ watch(
|
|
|
() => direction.value,
|
|
|
(newData, oldData) => {
|
|
|
nextTick(() => {
|
|
|
+ if (!game.value) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const gameScene = game.value.scene.getScene('GameScene');
|
|
|
if (newData > oldData) {
|
|
|
-
|
|
|
+ gameScene.cursors.left.isDown = false;
|
|
|
+ gameScene.cursors.right.isDown = true;
|
|
|
} else {
|
|
|
-
|
|
|
-
|
|
|
+ gameScene.cursors.left.isDown = true;
|
|
|
+ gameScene.cursors.right.isDown = false;
|
|
|
}
|
|
|
});
|
|
|
},
|