rafaskb / typing-label

A libGDX Label that appears as if it was being typed in real time.
MIT License
151 stars 20 forks source link

Unreadable text #4

Closed fgnm closed 5 years ago

fgnm commented 6 years ago

When I start my game for the first time typing labels are showed unreadable as the image above: photo_2018-04-28_10-23-21 Here should be written "TAP TO START". I create the label inside constructor of my Scene2D screen:

...
TypingLabel hint = new TypingLabel("{JUMP=0.13;2;0.8}" + mAssets.getString(Strings.TAP_TO_PLAY), mAssets.mFontStyle);
        GlyphLayout layout = new GlyphLayout(mAssets.mFontStyle.font, mAssets.getString(Strings.TAP_TO_PLAY));
        hint.setPosition((Constants.WORLD_WIDTH - layout.width) / 2, Constants.LAND_HEIGHT);
        addActor(hint);
...

If I add a {WAIT} before jump the problem appear to be solved on some devices, but on others not. So I think that timers and wait are not the right solution of this problem.

agmCorp commented 6 years ago

I have exactly the same problem.

fgnm commented 6 years ago

I've found a small workaround for this. Basically, at the end of act method in TypingLabel class, I check if that method is called for the first time, if yes force a restart() of the label, this seems to fix the issue but I hope that the developer could fix it in a better way..

My TypingLabel class:

public class TypingLabel extends Label {
...
    private boolean firstTime = true;
...

    @Override
    public void act (float delta) {
                ......
                if(firstTime) {
                    restart();
                    firstTime = false;
                }
        }
....
}
agmCorp commented 6 years ago

Could you please test this? It seems to fix this problem too, but I'm not 100% sure.

protected void saveOriginalText () {
    originalText.setLength(0);
    originalText.insert(0, this.getText());
    originalText.trimToSize();
    restart(); // <------ add this
}
fgnm commented 6 years ago

Tried but it produce a StackOverflowError, maybe we run different version of the library but in my restart() method I've an invalidate() call, so it cause an infinite loop. I'm using the latest available here on github

Mewel commented 5 years ago

In my case, this happens randomly on mobile phones with poor performance when text is displayed for the first time. But I haven't tried the fixes yet cause it's hard to reproduce.

rafaskb commented 5 years ago

Reference: https://m.youtube.com/watch?v=mEtuzvwIU20&t=7920