如果偏移 1 Phaser JS,我的图块集碰撞

问题描述 投票:0回答:1

我正在 Phaser 中制作一个自上而下的游戏,并使用 Tiled 作为图块地图。我设置了一些方块与玩家发生碰撞,但仅向下和右侧 1 个方块发生碰撞。

Picture of where the collision should be and where it actually is

玩家应该与橙色突出显示区域碰撞,但停在紫色突出显示区域。

这是我的图块地图、碰撞、玩家和碰撞调试器代码:

  const map = this.make.tilemap({key: 'map'});
  const tileset = map.addTilesetImage('RPG Nature Tileset', 'tiles')
  const floor = map.createStaticLayer('Tile Layer 1', tileset, 0, 0)
  const collision = map.createStaticLayer('Tile Layer 2', tileset, 0, 0)

  collision.setCollisionByProperty({collides: true});

  player = this.physics.add.sprite(2048, 2048, "player").setScale(0.4); //The size of the map is 4096px x 4096px which i might make smaller later
  this.physics.add.collider(player, collision);

  const debugGraphics = this.add.graphics().setAlpha(0.75);
  collision.renderDebug(debugGraphics, {
    tileColor: null, // Color of non-colliding tiles
    collidingTileColor: new Phaser.Display.Color(243, 134, 48, 255), // Color of colliding tiles
    faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Color of colliding face edges
  });
javascript phaser-framework tiled phaserjs tilesets
1个回答
0
投票

在没有看到资产的真实代码和尺寸的情况下,我只能猜测,问题与精灵有关。它比你想象的要大,所以碰撞箱也更大。

打开调试信息来检查这一点。如果这是问题,请修复精灵的图像,或者您可以使用方法

setSize(width, height)
修复碰撞框。

© www.soinside.com 2019 - 2024. All rights reserved.