今天在实现对一个Group使用fade in / fade out 淡出淡入动作的时候,
结果会使整个游戏界面出现闪烁,查找了半天,结果网站有人给出了方案,
结果会使整个游戏界面出现闪烁,查找了半天,结果网站有人给出了方案,
只需要修改一点就可以了。但是还不是很明白原因,所以先记录下来。
其实这两个效果都是对alpha进行改变。
static AlphaAction fadeIn(float duration)
Transitions from the alpha at the time this action starts to an alpha of 1.
static AlphaAction fadeOut(float duration)
Transitions from the alpha at the time this action starts to an alpha of 0.
上面的两种动作,其实都是alpha动作的特殊情况。
static AlphaAction alpha(float a, float duration)
Transitions from the alpha at the time this action starts to the specified alpha.
public class LianxiaoHint extends Group{
private RedNum m_starCount;
private RedNum m_score;
private Image m_lianxiao_bg;
//添加的代码
private Color color;
public LianxiaoHint() {
m_lianxiao_bg = new Image(Game.assets.allAtlas.findRegion("mmmmm"));
addActor(m_lianxiao_bg);
m_starCount = new RedNum();
addActor(m_starCount);
m_score = new RedNum();
addActor(m_score);
}
protected void setParent(Group parent) {
super.setParent(parent);
if (parent != null) {
clearActions();
Action remove = Actions.run(new Runnable() {
public void run() {
LianxiaoHint.this.remove();
}
});
setPosition((Game.width-getWidth())*0.5f, Game.height*0.5f);
this.addAction(Actions.sequence(Actions.fadeIn(0.1f),
Actions.repeat(2, Actions.sequence(Actions.fadeOut(0.1f),Actions.fadeIn(0.1f))),
Actions.parallel(Actions.moveTo(getX(), Game.height-300, 0.5f),Actions.alpha(0, 0.5f)),
remove));
}
}
@Override
public void draw(Batch batch, float parentAlpha) {
//添加的代码
color = batch.getColor();
batch.setColor(getColor());
super.draw(batch, parentAlpha);
//添加的代码
batch.setColor(color);
}
public void setStarCountAndScore(String starCount, String score){
m_starCount.setScore(starCount);
m_starCount.setPosition(0, 10);
m_lianxiao_bg.setPosition(m_starCount.getWidth()+10, 0);
m_score.setScore(score);
m_score.setPosition(m_lianxiao_bg.getX() + 225 + 10 - m_score.getWidth()*0.5f, 10);
setWidth(m_lianxiao_bg.getWidth()+m_starCount.getWidth());
setHeight(m_lianxiao_bg.getHeight());
}
}