0

我正在使用精灵和动画精灵。我使用了 16 帧动画精灵。对于左、右、上、下和最后 4 帧爆炸动画。

//animSprite.setCurrentTileIndex(leftCount);

当动画精灵与精灵碰撞时..我想显示最后 4 帧 5 秒。如何使用andengine。我尝试使用 Thread.sleep 但它不起作用。

//对于我正在使用的更新

scene.registerUpdateHandler(new IUpdateHandler() {
            @Override 
            public void reset() {

            }

            @Override
            public void onUpdate(final float pSecondsElapsed) {    
              checkCollision();
}

我可以在 logcat 中获得最后 4 帧数。但是屏幕没有更新..

如何刷新场景。

checkCollision()

{

if(sprite.collidesWith(animSprite))

  try
                   {

                    for (int i = 0; i < 4; i++) {                                         

                        animSprite.setCurrentTileIndex(animBlast);                    

                        Log.v("balst",""+animBlast);

                         animBlast++;

                         if (animBlast> 15) {

                             animBlast= 12;

                         }

                         Thread.sleep(10);

                    }

                   }
                   catch (Exception e) {

                       // e.printStackTrace();

        }
}
4

2 回答 2

2

因为AnimatedSprite你有一个sprite.animate(long[] pFrameDurations, int pFirstTileIndex, int pLastTileIndex, int loopCount)方法,它会执行一个loopCount帧循环,从pFirstTileIndexpLastTileIndex还定义了帧持续时间。我觉得这就是你要找的。

于 2011-08-01T06:41:38.583 回答
2

您不应该Thread.sleep()在更新线程中使用,因为这将阻止所有其他更新和重绘。而是研究AnimatedSprite.animate()Egor 所说的方法。

如果你想要类似于 sleep 的东西,那么使用TimerHandlerAndEngine 中的 s。更改falsetrue获取重复计时器。

TimerHandler my_timer = new TimerHandler(10, false,
    new ITimerCallback() {
        @Override
        public void onTimePassed(final TimerHandler pTimerHandler) {
            // Do your thing    
        }
});
scene.registerUpdateHandler(my_timer);
于 2011-08-04T16:01:29.107 回答