Jump to content

BUG: GO pointerdown not hit when camera scrollXY is changed and resolution is not 1


phaserlover
 Share

Recommended Posts

"phaser": "3.12.0-beta2",

Reproduce at http://jsfiddle.net/oyxbL16t/20/

Hi!

So when I change the scrollXY of the camera, and I try to click on a ImageGameObject it doesn't trigger the even pointerdown. If I randomly click in other places sometimes I hit the ImageGameObject, this makes me think there is a kind of offset problem in the calculation of the GO hit.

 

// Game

const config = {
  width: bbox.width,
  height: bbox.height,
  type: Phaser.AUTO,
  canvas: this.canvas,
  backgroundColor: '#091326',
  resolution: window.devicePixelRatio,
  render: {
    antialias: true,
    autoResize: true,
  },
  scene: {
    preload: this.preload,
    create: this.create,
    update: this.update,
  }
};
this.game = new Phaser.Game(config);

// In create

this.hammer.on('pinchmove', (event) => {
  mainCamera.zoom = (mainCamera.zoom * 0.9 + mainCamera.zoom * event.scale * 0.1);
});
this.hammer.on('panmove', (event) => {
  this.pan = {x: event.deltaX, y: event.deltaY};
});
this.hammer.on('panend', (event) => {
  this.pan = undefined;
  this.previousPan = undefined;
});

// GO creation

planetsGO[planet.id] = {
  planet: scene.add.image(planet.x, planet.y, textureId),
  healthBar: new HealthBar(scene, planet),
};
planetsGO[planet.id].planet.displayWidth = planet.radius * 2;
planetsGO[planet.id].planet.displayHeight = planet.radius * 2;
planetsGO[planet.id].planet.setInteractive();
planetsGO[planet.id].planet.on('pointerdown', () => {
  this.props.onPlanetIdClick(planet.id);
});

// In update loop

if (this.pan) {
  if (this.previousPan) {
    mainCamera.scrollX += (this.previousPan.x - this.pan.x) / mainCamera.zoom;
    mainCamera.scrollY += (this.previousPan.y - this.pan.y) / mainCamera.zoom;
  }
  this.previousPan = {...this.pan};
}

image.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...