为了账号安全,请及时绑定邮箱和手机立即绑定

无法旋转汽车且瓦片地图不完全可见

无法旋转汽车且瓦片地图不完全可见

慕的地8271018 2022-12-09 19:20:16
我正在尝试将以下 Phaser2 示例 ( https://phaser.io/examples/v2/tilemaps/fill-tiles ) 移植到 Phaser3 中。我遇到两个问题:我无法旋转车辆,因为左/右键不起作用。我无法让 tilemap 正确显示,它似乎被切断了。    import Phaser from "phaser";        const config = {      type: Phaser.AUTO,      parent: "phaser-example",      width: 800,      height: 600,      physics: {        default: 'arcade'      },      scene: {        preload: preload,        create: create,        update: update,        render: render      }    };        const game = new Phaser.Game(config);    let cursors;    let player;    let map;    let speed = 0;        function preload() {      this.load.tilemapTiledJSON('desert', 'desert.json');      this.load.image('tiles', 'https://examples.phaser.io/assets/tilemaps/tiles/tmw_desert_spacing.png')      this.load.image('car', 'http://labs.phaser.io/assets/sprites/car90.png')    }        function create() {      map = this.make.tilemap({ key: 'desert' });      const tiles = map.addTilesetImage('Desert', 'tiles');      const layer = map.createDynamicLayer('Ground', tiles, 0, 0);          cursors = this.input.keyboard.createCursorKeys();      player = this.physics.add.sprite(450, 80, 'car');          this.cameras.main.startFollow(player, true, 0.05, 0.05);    }        function update() {          // Drive forward if cursor up key is pressed down          if (cursors.up.isDown && speed <= 400) {        speed += 10;      } else {        if (speed >= 10) {          speed -= 10        }      }          // Drive backwards if cursor down key is pressed down          if (cursors.down.isDown && speed >= -200) {        speed -= 5;      } else {        if (speed <= -5) {          speed += 5        }      }          // Steer the car          if (cursors.left.isDown) {        player.body.angularVelocity = -5 * (speed / 1000);      } else if (cursors.right.isDown) {        player.body.angularVelocity = 5 * (speed / 1000);      } else {        player.body.angularVelocity = 0;      }    我怎样才能解决这个问题?
查看完整描述

1 回答

?
智慧大石

TA贡献1946条经验 获得超3个赞

我将代码加载到一个没有资产的空白项目中,并且能够看到缺少对象的图像旋转。然而,看起来速度对角旋转的依赖性太低了。如果你减少用于计算角速度的速度比例的减少,你可以让汽车转得更快。证明 -> https://stackblitz.com/edit/phaser-2-example-so


查看完整回答
反对 回复 2022-12-09
  • 1 回答
  • 0 关注
  • 171 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号