rafaskb/typing-label

Setting the color.a of a TypingLabel actor makes the FADE token not work properly.

UnbackedFan opened this issue · 11 comments

I have a use case in my app where I need to apply a scene2d fade Action to a TypingLabel while it's currently applying the FADE token. However, when changing the alpha channel of the TypingLabel's color, the FADE effect is ignored.

The code below works as expected. The fading occurs normally.

TypingLabel test = new TypingLabel("", Utils.getDefaultLabelStyle(MY_GAME.smallFont));
test.getColor().a = 1f;
test.restart("{SLOWER}{FADE=0;1;2.5} THIS IS A TEST THIS IS A TEST{ENDFADE}");

However, in this code, the fading effect is ignored.

TypingLabel test = new TypingLabel("", Utils.getDefaultLabelStyle(MY_GAME.smallFont));
test.getColor().a = 0.8f;
test.restart("{SLOWER}{FADE=0;1;2.5} THIS IS A TEST THIS IS A TEST{ENDFADE}");

That's an interesting bug, thanks for reporting it!
Recently @tommyettinger rewrote how color is applied to glyphs in TypingLabel to make it compatible with the next libGDX major release, I wonder if the issue is also present in his branch.

My pleasure, other than that, I find this library great!

I tried it with @tommyettinger branch #25 and the issue is still there.

OK, I'll take a look in my branch, maybe the code will be similar.

Huh, 37 minutes later I have a fix. It's a weird one. I had to avoid calling the superclass Label's draw() method in TypingLabel.draw(), because Label does its own tint() on the BitmapFontCache that can override what TypingLabel does. I also have to do some maintenance to track the color used for tinting (including parentAlpha) separately from the glyph colors. This should be fairly straightforward to bring over into the current version, but I'm not 100% sure on that -- I might be using some of the changed aspects of color handling in my PR and libGDX 1.10.1 .

Sounds great. I can test it in my app if needed. Has the artifact on JitPack been updated with the changes?

It looks like the latest commit built just recently, probably when you requested the SNAPSHOT build of my branch. In case it isn't working, https://jitpack.io/#tommyettinger/typing-label/run-color-fix-SNAPSHOT should have the current dependency. I really like how JitPack updates commits so readily, but their SNAPSHOT builds sometimes need Gradle to be told to refresh dependencies, if an older version is still considered the most current on your machine.

I'm not sure if I'm doing something wrong but I can't see the changes in the snapshot build. I tried invalidating the cache as well but it didn't work.

Hm, uh oh. I'm pretty sure you at least requested from JitPack the correct version, since it was built before I got to JitPack myself. I didn't want to change the default behavior of the demo, so I put comments in that have your repro text and effects, and also put in a commented line that sets the alpha to 0.5f. With the THIS IS A TEST text and 0.5 alpha, I get:

Image animation preview

I think I also slowed down the fade animation so I could see it better.

You can try directly requesting a specific commit on my repo, in my PR branch, with: implementation 'com.github.tommyettinger:typing-label:run-color-fix-e866065fcd-1' ; this seems the most likely way to ensure you have the current version. Also, make sure you don't simultaneously have conflicting dependencies on rafaskb/typing-label and tommyettinger/typing-label . I hope this fix is actually working for other people than just me...

I've testing it for my use case and it seems to work fine :) The TypingLabel fades properly with fade actions while it's still typing.

@tommyettinger am I correct to assume this issue is fixed with your latest changes in PR #25? Running the test on my end with the issue26.txt and enabling label.getColor().a = 0.5f produce the result you showed in the video above, which I believe is the expected outcome right?
If so I can close this, as I'm about to merge the PR and push a new release 😁