Jump to content

How to deal with pixel ratio and PIXI.Text ?


JDW
 Share

Recommended Posts

Hello,

 

Thanks to the amazing v2 of PixiJS, managing devicePixelRatio has become a lot easier.

 

However I'm still not very sure of how everything works and I'm wondering how I should deal with my PIXI.Text ?

 

If I have a DisplayObjectContainer, on a retina display (ratio = 2), can I draw a text, let's say 16px height, into a 8px "retina" height ?

I know how to do it with PIXI.BitmapText, it's easy because I only have to load a _@2x BitmapFont and it works fine. But what about classic text ? 

 

Thanks a lot !

 

Regards,

JDW.

Link to comment
Share on other sites

  • 3 weeks later...

"every text looks blurred on mobile device because of this"

Maybe that's caused by automatic scaling of canvas element?

I use this code to work around that:

<head lang="en">......    <meta id="viewport" name="viewport">    <script>     var viewportScale = 1 / window.devicePixelRatio;    document.getElementById('viewport').setAttribute('content', 'user-scalable=no, initial-scale=' + viewportScale);     </script> .....     appWidth = document.body.clientWidth;    appHeight = document.body.clientHeight;    renderer = new PIXI.CanvasRenderer(appWidth, appHeight); 
Link to comment
Share on other sites

Thanks for the help, but no, the "blurry" thing is normal, because PIXI create a texture with a resolution of "1", then scale it to the current resolution.

 

What I need to know is how to create a Text texture with the correct resolution.

Link to comment
Share on other sites

  • 3 weeks later...

Thanks to jagi on github for helping me :

 

PIXI.Text is the only DisplayObject that I know of with his own "resolution" property.

 

So you need to set the resolution to your actual device pixel ratio everytime you create a new PIXI.Text object.

 

var highDensityText = new PIXI.Text("PIXI's great !");

highDensityText.resolution = yourDevicePixelRatio;

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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