【问题标题】:Thread.sleep for animation (Andengine)用于动画的 Thread.sleep (Andengine)
【发布时间】:2012-12-01 01:08:52
【问题描述】:

我正在使用精灵和动画精灵。我使用了 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();

        }
}

【问题讨论】:

    标签: android andengine


    【解决方案1】:

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

    【讨论】:

    • 它工作正常,谢谢,在 andengine 中可以使用 Thread.sleep 方法
    • @JohnRaja,从来没有觉得需要这个
    【解决方案2】:

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

    如果您想要类似于睡眠的东西,请使用 AndEngine 中的TimerHandlers。将false 更改为true 以获得重复计时器。

    TimerHandler my_timer = new TimerHandler(10, false,
        new ITimerCallback() {
            @Override
            public void onTimePassed(final TimerHandler pTimerHandler) {
                // Do your thing    
            }
    });
    scene.registerUpdateHandler(my_timer);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-07
      相关资源
      最近更新 更多