我尝试创建简单的mesured时间标签。我尝试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。
答案 0 :(得分:0)
不要使用这些会在每次更新时更新的处理程序(在您的情况下,它会多次加载所有资源)。尝试使用一个处理程序本身。并在完成加载资源后取消注册此句柄。