与CountDown Timer连接的错误无法在未调用Looper.prepare()的线程内创建处理程序

时间:2013-12-03 23:23:21

标签: android andengine

我在标题中遇到以下代码的错误: 任何人都可以帮我解决这个问题吗? 我将非常感激。

    final Sprite mPocisk = new Sprite(0, 0,this.mPocisk, getVertexBufferObjectManager());
    scene.attachChild(mPocisk);
    mPocisk.setVisible(false);
    final Katapulta S_katapulta_wystrzelona = new Katapulta(10, 300, this.mKatapulta_wystrzelona, getVertexBufferObjectManager());
    final Katapulta S_katapulta_zaladowana = new Katapulta(10, 300, this.mKatapulta_zaladowana, getVertexBufferObjectManager()){
        @Override
        public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            setVisible(false);
            S_katapulta_wystrzelona.setVisible(true);
            double time = rzut.t;
// I think following code generate error
                 new CountDownTimer((long) (time*100), 500) {
                     public void onTick(long millisUntilFinished) {
                        double time_copy=+0.5; 
                        System.out.println("test");
                        mPocisk.setPosition((float)rzut.getXfor(time_copy), (float)rzut.getYfor(time_copy));
                        mPocisk.setVisible(true); 
                     }
                     public void onFinish() {
                     }
                  }.start();
            return true;
        }
    };

1 个答案:

答案 0 :(得分:0)

我以下列方式解决了这个问题

engine.registerUpdateHandler( new TimerHandler(1.0f, new ITimerCallback()
    {

        @Override
        public void onTimePassed(final TimerHandler pTimerHandler)
        {
            //Your task
        }
     }));