Jump to content

setText doesn't allow empty strings


Recommended Posts

I wrote an edit box in Phaser which is working perfectly apart from one detail.

When I try to delete existing text and enter a new string, it cannot delete the first character.


After some poking around I found it is due to this code being carried over into Phaser:

PIXI.Text.prototype.setText = function(text){this.text = text.toString() || ' ';this.dirty = true;};

When I delete the last character in a string then try to assign the now empty string to the Text.text field, it is being replaced with a space.


Apparently this was to prevent a PIXI crash when an empty string was encountered... but maybe that's been fixed now?  Is there a reason why I shouldn't try to fix this by using '' instead of ' '?  Empty strings are normally quite acceptable, but perhaps there's something deeper inside which I haven't spotted yet.


I've already changed Phaser and it seems stable with the change, but as Phaser likes to mimic PIXI when functions are duplicated/similar I probably can't get that into the main branch without a similar change to PIXI.

Link to comment
Share on other sites

  • 3 weeks later...

I had to move back to paying work for a while so I haven't tested it thoroughly... The changes (to both Phaser and PIXI) didn't have any obvious ill consequences and they did fix the problem with the unwanted space.  I'd need to see a bug report for the original PIXI crash to be completely certain though.

My change was to simply remove the space from the single quotes in both pieces of duplicated code.

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