如何在libgdx中调整BitmapFontCache的alpha?
我正在为libgdx应用程序中的一些文本设置动画,希望标签文本淡入并移动(例如,类似于此) 我可以移动和更改其他对象(例如精灵)的alpha,也可以移动BitMapFontCache。然而,我无法改变BitmapFontChage的alpha 声明:如何在libgdx中调整BitmapFontCache的alpha?,libgdx,tween,Libgdx,Tween,我正在为libgdx应用程序中的一些文本设置动画,希望标签文本淡入并移动(例如,类似于此) 我可以移动和更改其他对象(例如精灵)的alpha,也可以移动BitMapFontCache。然而,我无法改变BitmapFontChage的alpha 声明: message = new BitmapFontCache(messageFont, true); message.setWrappedText("some text", 10.0f, 10.0f, 10.0f); message.setAlpha
message = new BitmapFontCache(messageFont, true);
message.setWrappedText("some text", 10.0f, 10.0f, 10.0f);
message.setAlphas(0.0f);
在我的screen类中,我重写render方法,并在renderer类上调用.draw(),该类本质上只是一个message.draw(批处理)代码>呼叫
@Override
public void render(float delta) {
...
try{
batch.begin();
feedbackRenderer.draw(batch);
tweenManager.update(delta);}
finally{
batch.end();
}
}
然后作为时间线的一部分,我把这两个二人组称为。(是的,它们被包装在.push()中,我启动了我的tweenManager:)
BitmapFontCacheAccessor尝试将BitmapFontCache的Alphas()设置为:
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;}
}...
公共类BitmapFontCacheAccessor实现TweenAccessor{
公共静态最终整数位置_X=1;
公共静态最终intα=2;
@凌驾
公共void集合值(BitmapFontCache目标、int-TweentType、float[]新值){
开关(二十种类型){
案例位置X:
float y=target.getY();
target.setPosition(新值[0],y);
打破
案例α:
target.setAlphas(newValues[0]);
中断;}
}...
它移动标签(=>。设置位置(x,y)有效!),但甚至不接触alpha。这种完全相同的方法适用于精灵,精灵可以很好地淡入
在为BitmapFontCache使用tweening alpha时是否存在一些问题?可能吗
非常感谢!经过一个小时的调试,我找到了这种有趣行为的原因
Libgdx的BitmapFontCache没有getAlphas()
方法
因此,为了获得alpha通道,我使用了getColor().a
然而,这两个并不总是同步的。这种行为是非常随机的,我自己也不太确定它何时同步,何时不同步(例如,在上面的问题中,淡出会起作用,但淡入不会)
解决方案是更改和声明两个alpha通道
BitmapFontCache的定义:
message = new BitmapFontCache(messageFont, true);
message.setColor(1,1,1,0);
message.setAlphas(0);
和内部的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;
对于你,绝望的流浪者,我回答这个问题是为了让你能在有限的时间里比我过得更好。展示你绘制位图的代码嘿,我已经添加了代码。在淡入二人组之后,如果我称之为淡出二人组(例如从1.0降到0.0),它会变得更为复杂它会消失!?我不确定该怎么做。你具体渲染字体的部分在哪里?我不确定我是否理解你的评论。我添加的部分就是它。message.draw(batch)
,每次渲染(float delta)时都会调用它
被调用。我想我想看看feedbackRenderer.draw(批处理)中有什么内容;
case ALPHA:
//first alpha channel
target.setAlphas(newValues[0]);
//second alpha channel
Color c = target.getColor();
c.a = newValues[0];
target.setColor(c);
break;