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.2k stars 7.1k forks source link

`Phaser.Scale` for pixel-perfect games #6629

Closed musjj closed 9 months ago

musjj commented 1 year ago

https://photonstorm.github.io/phaser3-docs/Phaser.Scale.ScaleModes.html

A scaling mode that scales the canvas up by integer scales (x2, x3, etc.) to fit the target area would be useful for pixel-perfect games. Of course, it should not scale the canvas down if the target area is smaller than the canvas

samme commented 1 year ago

This can be done with scale mode FIT (or similar) and scale.setSnap().

I can't remember if I've requested already, but I would like snap options in the scale config, e.g.,

new Phaser.Game({
  pixelArt: true,
  scale: {
    mode: Phaser.Scale.FIT,
    width: 320,
    height: 200,
    snap: { width: 320, height: 200 },
    min: { width: 320, height: 200 },
  }
});
musjj commented 1 year ago

Thanks, that works for me!

musjj commented 1 year ago

Ah but still, having it as a built-in option would be nice, so I'll keep this open.

photonstorm commented 9 months ago

Thank you for submitting this feature request. We have implemented this and the feature has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.