How to tween alpha of a BitmapFontCache in libgdx? -
i animating text in libgdx application , label text fade-in , move (e.g. similar jsfiddle).
i can move, , change alpha of other objects (e.g. sprites) , can move bitmapfontcaches. can't alpha of bitmapfontchage change.
declaration:
message = new bitmapfontcache(messagefont, true); message.setwrappedtext("some text", 10.0f, 10.0f, 10.0f); message.setalphas(0.0f);
in screen class, override render method, , call .draw() on renderer class, (among other things) message.draw(batch);
call.
@override public void render(float delta) { ... try{ batch.begin(); feedbackrenderer.draw(batch); tweenmanager.update(delta);} finally{ batch.end(); } }
then a part of timeline call these 2 tweens. (yes, wrapped in .push( ) , start tweenmanager:)
tween.to(message, bitmapfontcacheaccessor.position_x, animationduration) .target(35.0f) tween.to(message, bitmapfontcacheaccessor.alpha, animationduration) .target(1.0f)
the bitmapfontcacheaccessor tries setalphas() of bitmapfontcache such:
public class bitmapfontcacheaccessor implements tweenaccessor<bitmapfontcache> { public static final int position_x = 1; public static final int alpha = 2; @override public void setvalues(bitmapfontcache target, int tweentype, float[] newvalues) { switch (tweentype) { case position_x: float y = target.gety(); target.setposition(newvalues[0], y); break; case alpha: target.setalphas(newvalues[0]); break;} }...
it moves label (==> .setposition(x, y) works!), not touch alpha. exact same approach works sprites, fade in nicely.
is there perhaps catch when tweening alpha bitmapfontcache? possible?
many thanks!
after hour of debugging have found reason funny behavior.
- libgdx's bitmapfontcache not have
getalphas()
method- therefore, alpha channel used
getcolor().a
- however, these 2 not synced. behavior quite random, myself not quite sure when syncs , when doesn't (f.ex. in question above, fade-outs work, fade-ins wouldn't)
the solution change , declare both alpha channels.
definition of bitmapfontcache:
message = new bitmapfontcache(messagefont, true); message.setcolor(1,1,1,0); message.setalphas(0);
and inside tweenaccessor:
case alpha: //first alpha channel target.setalphas(newvalues[0]); //second alpha channel color c = target.getcolor(); c.a = newvalues[0]; target.setcolor(c); break;
to you, hopeless wanderer, address answer can spend of finite number of minutes of life better did.
Comments
Post a Comment