Jump to content

Text object shows as black box for long strings


CraigBall
 Share

Recommended Posts

Hardware: Sony Experia Z5 premium. Maximum texture size is 4096, devicePixelRatio is 3, screen resolution is 1920x1080.
PIXI: Version 4.2.2, renderer is WebGL.

 

When we create a PIXI text object that has a long string in it, it turns to a black box. After investigation, it looks like its when the width of the text object is 1366 or over. We think a black box is shown because a texture cannot be created as 1366 is larger than "Maximum Texture Size / devicePixelRatio", although I don't know this for sure.

Here's code to replicate.

   var renderOptions = {
       resolution: window.devicePixelRatio,
       backgroundColor : 0x1099bb
   };

   var stage = new PIXI.Container();
   var renderer = new PIXI.autoDetectRenderer(500, 200, renderOptions);
   document.body.appendChild(renderer.view);

   // This text shows a black box
   var text = new PIXI.Text("");
   while (text.width < 1366) {
       text.text += String.fromCharCode(65+Math.floor(Math.random()*26) );
   }
   stage.addChild(text);

   // This text works
   var text2 = new PIXI.Text(text.text.substr(0, 20));
   text2.position.y = 50;
   stage.addChild(text2);

   renderer.render(stage);

 

We tried to set resolution on the text object but this had no effect as this is overwritten on the render pass (PIXI line 21334):-

 

Text.prototype.renderWebGL = function renderWebGL(renderer) {
    if (this.resolution !== renderer.resolution) {
        this.resolution = renderer.resolution;
        this.dirty = true;
    }

    this.updateText(true);

    _Sprite.prototype.renderWebGL.call(this, renderer);
};

 

Is there a reason why resolution is enforced? If this is the case, then you can never create a text objects with a string that will show across the length of this phone screen. Should I be approaching this a different way?

Thanks,

 

Craig

Link to comment
Share on other sites

First, personally, I wouldn't use window.devicePixelRatio as the resolution modifier. If the resolution of the game is 960x540, and you use a devicePixelRatio of 3, then you're rendering now at a resolution of 2880x1620, which is pretty insane. By all means increase the resolution based on if the device screen is higher, or the device is more powerful, but I wouldn't link it necessarily to window.devicePixelRatio, and test out the visual quality yourself if you can see a difference. 

Second: I don't like the code you've pasted which forces the resolution of the text to match the resolution of the renderer. I believe you should be able to override it; so I might do a PR to allow that behaviour.

Right now though you can achieve what you want by overriding this behaviour. Add the following code before you create the PIXI renderer. Now any resolution you set after creating the text will be the resolution used for any future updates of text;

Object.assign( PIXI.Text.prototype, {
	renderWebGL: function( renderer ) {
		this.updateText( true );

		PIXI.Sprite.prototype.renderWebGL.call( this, renderer );
	},
	renderCanvas: function( renderer ) {
		this.updateText( true );

		PIXI.Sprite.prototype._renderCanvas.call( this, renderer );
	}
} );

 

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