我发现LIBGDX分配了很多变量(不是我的任何方法)。我刚刚运行游戏几秒钟,我已经在 DDMS-> Allocation Tracker 中获得了32000行。分配的方法是getPalmRejection
,createFromParcel
和nativeReadString
。在几秒钟内完成这么多的分配是否正常?
我得到60FPS,但有时会降到58-59,这很重要,因为我在游戏中使用了与帧速率无关的运动,当发生FPS掉落时,我得到了很多sprite-jolts(精灵跳跃)。
以下是堆栈跟踪:
**createFromParcel**
at android.graphics.Rect$1.createFromParcel(Rect.java:562)
at android.graphics.Rect$1.createFromParcel(Rect.java:557)
at com.samsung.android.multiwindow.MultiWindowStyle.readFromParcel(MultiWindowStyle.java:278)
at com.samsung.android.multiwindow.MultiWindowStyle.<init>(MultiWindowStyle.java:141)
at com.samsung.android.multiwindow.MultiWindowStyle$1.createFromParcel(MultiWindowStyle.java:284)
at com.samsung.android.multiwindow.MultiWindowStyle$1.createFromParcel(MultiWindowStyle.java:282)
at com.samsung.android.multiwindow.IMultiWindowFacade$Stub$Proxy.getMultiWindowStyle(IMultiWindowFacade.java:467)
at com.samsung.android.multiwindow.MultiWindowFacade.getMultiWindowStyle(MultiWindowFacade.java:53)
at android.app.ActivityThread.getAppMultiWindowStyle(ActivityThread.java:5368)
at android.app.ContextImpl.getAppMultiWindowStyle(ContextImpl.java:2698)
at android.content.ContextWrapper.getAppMultiWindowStyle(ContextWrapper.java:690)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6324)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6307)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6278)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6243)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6483)
**<init>**
at com.samsung.android.multiwindow.MultiWindowStyle.<init>(MultiWindowStyle.java:40)
at com.samsung.android.multiwindow.MultiWindowStyle$1.createFromParcel(MultiWindowStyle.java:284)
at com.samsung.android.multiwindow.MultiWindowStyle$1.createFromParcel(MultiWindowStyle.java:282)
at com.samsung.android.multiwindow.IMultiWindowFacade$Stub$Proxy.getMultiWindowStyle(IMultiWindowFacade.java:467)
at com.samsung.android.multiwindow.MultiWindowFacade.getMultiWindowStyle(MultiWindowFacade.java:53)
at android.app.ActivityThread.getAppMultiWindowStyle(ActivityThread.java:5368)
at android.app.ContextImpl.getAppMultiWindowStyle(ContextImpl.java:2698)
at android.content.ContextWrapper.getAppMultiWindowStyle(ContextWrapper.java:690)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6324)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6307)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6278)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6243)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6483)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
**getPalmRejection**
at android.view.ViewRootImpl.getPalmRejection(ViewRootImpl.java:3895)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6389)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6307)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6278)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6243)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6483)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6456)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6502)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:571)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
编辑:一个非常可能的原因是三星设备的MultiWindow功能。分配的另一个可能原因是游戏屏幕的 touchDown 事件的方法:
@Override
public boolean touchDown (int x, int y, int pointer, int button) {
if ( (!spaces_can_explode && !paused_game_screen) && !spaces.exploded_finished && hud_display.startTimerFinished){
hud.touchDown(x, y, pointer, button, spaces, spaceship_bounding_rectangle, display_fud_camera, hud_display.startTimerFinished);
}
return false;
}
public void touchDown(int x, int y, int pointer, int button, Ship spaces, Rectangle shootHud, OrthographicCamera hud_cam, boolean startTimerFinished){
hud_cam.unproject(touchPoint.set(x, y,0));
pressed_middle_shoot = shootHud.contains(touchPoint.x, touchPoint.y);
if(!(pointer>1) && spaces.touch_upped){
pressed_left = (x < screen_sizewp3) && !pressed_middle_shoot;
pressed_right = (x > screen_sizewo2p3) && !pressed_middle_shoot;
pressed_middle = (!pressed_left && ! pressed_right);
if(!spaces.reversed_rotation ){
if(pressed_middle){
pressed_shoot = pressed_middle_shoot;
spaces.pressed_shoot = pressed_middle_shoot;
pressed_accel = !pressed_shoot;
spaces.pressed_accel = !pressed_shoot;
}
else if(pressed_left && !pressed_right){
if(spaces.sprite.getX() > spaces_maxleftplus){
spaces.touchDOWN(x, y, pointer, button, pressed_left, pressed_right, pressed_middle);
}
} else if (pressed_right && !pressed_left){
if(spaces.sprite.getX() < spaces_maxrightminus){
spaces.touchDOWN(x, y, pointer, button, pressed_left, pressed_right, pressed_middle);
}
}
}
}
pressed_left_hud = pressed_left;
pressed_right_hud = pressed_right;
pressed_shoot_once = pressed_middle_shoot;
}