libgdx: fadeIn和fadeOut 动作 - 导致屏幕闪烁

今天在实现对一个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());
	}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值