phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.14k stars 7.1k forks source link

Pixel distortion / shifting when using setDepth() #6692

Closed rb1147x closed 2 months ago

rb1147x commented 11 months ago

Version

Description

Game objects appear to visually shift slightly when interacted with, which appears to be based on setDepth(). Although, this may not actually be the culprit. Here's an example:

pixelshifting

Which you can interact with here: https://jsitor.com/3vkO_hzB0S

I had made a forum post about this: https://phaser.discourse.group/t/pixel-distortion-shifting-issue/13774 so the full context is available there, but after commenting out setDepth(), which is being used to bring the object to the front so that it can be dragged over other game objects, the problem goes away.

On the forum post, there was a solution posted to specifically set roundPixels to false on the camera, which does solve this problem. However, this seems like a bug? Why would setting a game object's depth cause this visual issue? Also, this problem does not happen in 3.60.0.

Thanks.

Example Test Code

https://jsitor.com/3vkO_hzB0S

Additional Information

KingCosmic commented 11 months ago

seems to only be an issue in WEBGL and not CANVAS, also seems to be an issue with having multiple scenes render, I consolidated your example test code into a single scene (with some minor adjustments) https://jsitor.com/z3lB4A5yWE and can't get it to reproduce afterwards. I'm not versed enough in the webgl renderer to dive much further but hopefully this helps Richard or someone else track this down.

rb1147x commented 11 months ago

Thanks for taking a look. My original example was born from the project I'm working on that uses two scenes - one for the game world and one for drawing UI objects and handling UI interactions (e.g. dragging game items to your inventory). Although the issue presented itself while using setDepth() and there's at least a temporary fix by setting the UI scene's camera roundPixels property to false, maybe the root issue is more in line with what you've discovered - using webGL and multiple scenes.

samme commented 6 months ago

I reproduced this with 1 Graphics, 1 Image, and moveUp(): https://phaser.io/sandbox/q89fEzzs

photonstorm commented 2 months ago

Thanks for that example @samme - this was a roundPixels issue and is fixed in v3.85 - you can confirm this in the sandbox by changing the version to 'dev'.