Skip to content

Commit

Permalink
BaseCamera.renderRoundPixels is a new read-only property that is se…
Browse files Browse the repository at this point in the history
…t during the Camera `preRender` method every frame. It is true if the Camera is set to render round pixels and the zoom values are integers, otherwise it is false. This is then fed into the MultiPipeline when rendering sprites and textures.
  • Loading branch information
photonstorm committed Oct 10, 2024
1 parent 13177a4 commit 8e432ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/cameras/2d/BaseCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,22 @@ var BaseCamera = new Class({
* @since 3.60.0
*/
this.isSceneCamera = true;

/**
* Can this Camera render rounded pixel values?
*
* This property is updated during the `preRender` method and should not be
* set directly. It is set based on the `roundPixels` property of the Camera
* combined with the zoom level. If the zoom is an integer then the WebGL
* Renderer can apply rounding during rendering.
*
* @name Phaser.Cameras.Scene2D.BaseCamera#renderRoundPixels
* @type {boolean}
* @readonly
* @default true
* @since 3.86.0
*/
this.renderRoundPixels = true;
},

/**
Expand Down
5 changes: 4 additions & 1 deletion src/cameras/2d/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ var Camera = new Class({
var zoomY = this.zoomY;
var matrix = this.matrix;

this.renderRoundPixels = (this.roundPixels && Number.isInteger(zoomX) && Number.isInteger(zoomY));

var originX = width * this.originX;
var originY = height * this.originY;

Expand Down Expand Up @@ -589,7 +591,8 @@ var Camera = new Class({
Math.floor(this.x + originX + 0.5),
Math.floor(this.y + originY + 0.5),
this.rotation,
zoomX, zoomY);
zoomX, zoomY
);

matrix.translate(-originX, -originY);

Expand Down

0 comments on commit 8e432ae

Please sign in to comment.