AndEngine中的动画精灵播放超过一次

3

我试图只对一个精灵进行动画,但它却被动画了两次,有人可以帮我吗??这是代码:

    CuttingLineEffect(float x, float y, TiledTextureRegion line_region)
{
    super(x, y, line_region);
    this.animate(60, 1);
    this.mPhysicsHandler = new PhysicsHandler(this); 
    this.registerUpdateHandler(this.mPhysicsHandler);
    this.setPosition(x-this.getWidth()/2-50+this.getWidth()/2,y+50);
}

@Override
protected void onManagedUpdate(float pSecondsElapsed) {

    if(!set)
    {
        MainMenu.LineList.add(this);
        set = true;
    }
    if(!this.isAnimationRunning() && !time_to_unload)
    {
        time_to_unload = true;

    }


    super.onManagedUpdate(pSecondsElapsed);
};
2个回答

3
Animate() 的第二个参数是你想循环播放该动画的次数。因为你只想播放一次,所以可以直接使用。
this.animate(60,0);

但这不是一次性的动画,而是在精灵的生命周期内都会进行动画。 - Jawad Amjad
这个.animate(60,false)怎么样? - Rohan
这根本没有动画 :( - Jawad Amjad
1
我最后的猜测是查看AnimatedSprite的源代码。this.animate(60, 0); - Rohan
我看到iAnimationListener中有一个onAnimationEnd()方法,你可以尝试实现该方法,并在其中调用sprite的stopAnimation()方法...我很好奇 :P - Rohan

3
Sprite.animate(100,false);
  • 100 --> 每帧的时间间隔
  • false --> 第二个参数是用来判断是否循环播放的。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接