Jump to content

How can I scale my game sharply?


Recommended Posts

I am making a game based on 16x16 sprites which I want to scale to fit the scree. The gameboard is 160 pixels wide.

The problem is, I cannot get the pixels to render sharply (as if I'd enlarge them using nearest neighbour resize in Photoshop).

I have styled the game canvas like so:

canvas {
    /*centre canvas*/
    padding: 0px;
    margin: 0px;
    margin: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    /*fit canvas to viewport*/
    min-height: 100vh;
    max-height: 100vh;
    min-width: 100vw;
    max-width: 100vw;
    object-fit: cover;
    -ms-interpolation-mode: nearest-neighbor;  // IE 7+ (non-standard property)
    image-rendering: -webkit-optimize-contrast; // Safari 6, UC Browser 9.9
    image-rendering: -webkit-crisp-edges; // Safari 7+
    image-rendering: -moz-crisp-edges; // Firefox 3.6+
    image-rendering: -o-crisp-edges; // Opera 12
    image-rendering: pixelated; // Chrome 41+ and Opera 26+

I have a boot state with the following init method:

export default class extends Phaser.State {
  init() {
    this.stage.backgroundColor = '#EDEEC9'
    this.smoothed = false
    this.fontsReady = false
    this.fontsLoaded = this.fontsLoaded.bind(this)

    this.scale.startFullScreen(true) // Display as fullscreen on devices that support fullscreen api
    this.game.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT
    this.stage.smoothed = false;

From what I can tell from this example `this.stage.smoothed` should ensure that the pixels renders crisply. However, they do not.

What do I need to do to get my images to render sharp?


Screen Shot 2018-08-03 at 17.35.32.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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