Android 安发动机更新计时器标签

Android 安发动机更新计时器标签,android,andengine,runnable,Android,Andengine,Runnable,我尝试创建简单的测量时间标签。我尝试RunnableHandler、Handler和activity.this.runOnUiThread()。每次我都会犯类似的错误 错误 03-07 03:34:40.057: E/AndroidRuntime(5670): java.lang.ArrayIndexOutOfBoundsException: length=90; index=90 03-07 03:34:40.057: E/AndroidRuntime(5670): at org.an

我尝试创建简单的测量时间标签。我尝试RunnableHandler、Handler和activity.this.runOnUiThread()。每次我都会犯类似的错误

错误

03-07 03:34:40.057: E/AndroidRuntime(5670): java.lang.ArrayIndexOutOfBoundsException: length=90; index=90
03-07 03:34:40.057: E/AndroidRuntime(5670):     at org.andengine.entity.text.vbo.HighPerformanceTextVertexBufferObject.onUpdateVertices(HighPerformanceTextVertexBufferObject.java:124)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at org.andengine.entity.text.Text.onUpdateVertices(Text.java:333)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at org.andengine.entity.shape.Shape.setSize(Shape.java:146)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at org.andengine.entity.text.Text.setText(Text.java:221)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at pl.newaxis.szyfraki.MainActivity.updateTimerText(MainActivity.java:224)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at pl.newaxis.szyfraki.MainActivity$5$1.run(MainActivity.java:181)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at android.os.Handler.handleCallback(Handler.java:733)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at android.os.Handler.dispatchMessage(Handler.java:95)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at android.os.Looper.loop(Looper.java:136)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at android.app.ActivityThread.main(ActivityThread.java:5081)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at java.lang.reflect.Method.invokeNative(Native Method)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at java.lang.reflect.Method.invoke(Method.java:515)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-07 03:34:40.057: E/AndroidRuntime(5670):     at dalvik.system.NativeStart.main(Native Method)
我当前的代码

@Override
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws IOException {
    final Thread backgroundLoading = new Thread(new Runnable() {
        @Override
        public void run() {
            loadResources();
            loadScenes();
            Handler refreshScene = new Handler(Looper.getMainLooper());
            refreshScene.post(new Runnable() {

                @Override
                public void run() {
                    loadingIndicator.detachSelf();
                    splash.detachSelf();
                    mEngine.setScene(mainScene);
                }
            });

        }
    });
    mEngine.registerUpdateHandler(new TimerHandler(1f, new ITimerCallback() {

        @Override
        public void onTimePassed(TimerHandler pTimerHandler) {
            backgroundLoading.start();
        }
    }));

    mEngine.registerUpdateHandler(new TimerHandler(1f, new ITimerCallback() {

        @Override
        public void onTimePassed(TimerHandler pTimerHandler) {
            // TODO Auto-generated method stub
            initLoadingAnimation();
        }
    }));

    pOnPopulateSceneCallback.onPopulateSceneFinished();

}


private void loadScenes() {
    mainScene = ((MenuController) mFrame.getModule("Menu")).createMainMenu();
    final Handler updateLabel = new Handler(Looper.getMainLooper());
    Font font = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32);
    font.load();
    //
    Float timerText = 0.0f;
    timerLabel = new Text(CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2, font, Float.toString(timerText), this.getVertexBufferObjectManager());
    TimerHandler mTime = new TimerHandler(0.1f, true, new ITimerCallback() {

        float time = 0.0f;

        @Override
        public void onTimePassed(TimerHandler pTimerHandler) {
            time += 0.1f;
            updateLabel.post(new Runnable() {

                @Override
                public void run() {
                    updateTimerText(time);

                }
            });

        }

    });

    mainScene.attachChild(timerLabel);
    mainScene.registerUpdateHandler(mTime);
}

void updateTimerText(float value) {
    timerLabel.setText(Float.toString(value));
}

你能告诉我我做错了什么吗?我将最新的AndEngine与GLES 2一起使用。

不要使用这些每次都会更新的处理程序(在您的情况下,它会多次加载您的所有资源)。尝试使用一个处理程序本身。并在加载完资源后注销此处理程序。

好的,我注意了注销,当调用
timerLabel.setText(Float.toString(value)),它会崩溃在文本标签中指定最小字符数AKS:)最小字符数帮助:)