Hi,
I’m working on a game with one interactive element, for which I created hitArea in scene’s start() function:
var hit_area = new Phaser.Geom.Rectangle(-17, -15, 34, 51);
this.myobject.setInteractive(hit_area, Phaser.Geom.Rectangle.Contains);
This works well until window is resized. My canvas has fixed size and is horizontally centered using CSS inside the window. But it seems like after resize, whole canvas with it’s content has moved but object’s hit Area stays in place and therefore is not aligned with object anymore.
When I resize window to original position, it is well aligned again.
When I start game with smaller window size, hit Area is aligned but after resize (stretch window width) it is offset from object to other side - e.g. still stays in same offset relative to window left border - but not accordind to canvas coordinates.
I tried to removeInteractive() and then setInteractive() with same arguments after each window resize but it is not working. Is there an option to reset hitArea after window is resized?
Thank you - I didn’t find the solution there but it pointed me in the right direction:
Rather than centering the canvas parent div via CSS - I stretched parent div across screen and centered canvas in phaser config using autoCenter: Phaser.Scale.CENTER_BOTH
This way the problem is solved allthough I’m not sure why setting position of the parent div causes this error.