Jump to content

Performance issue with cache=true in Text (simple example)


mise
 Share

Recommended Posts

perormance of this example goes to zero asymtotically but runs very smooth when cache=false:

same thing if you create new Text every update.

var text: any;

game.module(
    'game.main'
)
.body(() => {
game.addAsset('font.fnt');
game.Debug.enabled = true;
game.createScene('Main', {
    init: function() {
        text = new game.Text('', { font: 'font', cache: true });
      },
    update: () => {
        text.setText(Date.now());
    }
});

Link to comment
Share on other sites

  • 2 weeks later...

This is actually expected behavior. When you set cache property to true, the engine will render the whole content into one big sprite and use that for rendering instead of using one sprite for each character. Every time you change the text it has to render the big sprite again. So i would suggest to use cache only on text that you don't change constantly.

Link to comment
Share on other sites

Yeah, I figured that might be the case.

That at least explains why it would be slower in this case. I still don't see why performance would need to go down though. Are we keeping all cached sprites around forever by default? What would be the reason for keeping old ones around at all? Maybe if we switch between a couple of same texts, but at that point I would just swap visibility on multiple instances which could be way faster anyway.

I am mostly just curious at this point :)

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