Jump to content

Text Size Changes With Resolution


Recommended Posts

Hi, I'm trying to build my HUD with PIXI.Text, but am having problem that the text is bigger when resolution is larger. For example when l load the page with browser at 200% zoom then my HUD ends up being twice as big. I want the text to stay the same size thou - higher resolution should make it look crisper not larger. Any help/ideas for this? Thanks!

// create app
var app = new PIXI.Application({
    width: window.innerWidth,
    height: window.innerHeight,
    resolution: window.devicePixelRatio,
    autoResize: true,
    antialias: true,
    backgroundColor: 0xFFFFFF

// create text
var text = new PIXI.Text("TESTING");


Link to comment
Share on other sites

Thanks I double-checked and I'm on the latest pixi version 4.5.4. I tried setting the resolution like you said but it didn't have any effect. I looked in Text.prototype.renderWebGL and it checks and sets the resolution to renderer.resolution automatically each frame. I changed that to always set it to 1 and the text is still 2X size but it's blurry (which makes sense I think if browser is stretching it to match renderer's resolution).

Link to comment
Share on other sites

OK I tried that but it's the same. Hmm, maybe I should explain what I'm after better thou. For other elements I had created a texture from html-canvas (if resolution is 2X then I draw twice as big and use 2 for texture's resolution). So on the screen it ends up being the same size and isn't blurry, whether resolution is 1X or 2X. I really want to achieve the same thing with the text :)

Link to comment
Share on other sites

Aha! Dividing font size by resolution seems to work to preserve size and quality (mostly), like this:

text.style.fontSize = (FONT_SIZE / app.renderer.resolution) + "px";

LOL once I explained what I wanted to do the answer popped out at me :)

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...