首页 > 解决方案 > 游戏冻结并显示连续执行 6 个布局。跳过

问题描述

好的,所以我已经尝试在没有游戏引擎的 2D 纯 android中平滑跳跃一周了。我现在正在使用ScheduledThreadPoolExecutor

所以我有一个名为 FPS 的变量。这是角色在达到 180 Y 值之前必须上升多少次;

注意:FPS在整个游戏中并不是真正的每秒帧数。

FPS设置为 45 时,应用程序永远不会死机(除非我反复向跳转按钮发送垃圾邮件)

但是在 90 上,当我玩游戏时,游戏会冻结,logcat 会显示:

E/WindowManager: Performed 6 layouts in a row. Skipping

我使用什么(例如:Handler RunnableThread),应用程序并不重要

下面是跳转代码:

    public void jump() {

    final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);

    if(!isRunning) {
        executor.scheduleWithFixedDelay(new Runnable() {
            boolean moveUpBln = true;
            int timesLooped = 0;
            float FPS = 90; //Never freezes with value of 45 (or under)
            float charMovementFPS = 180 / FPS;

            @Override
            public void run() {
                if(moveUpBln) {
                    isRunning = true;

                    characterModel.setY(characterModel.getY() - charMovementFPS);
                    if (timesLooped == FPS || timesLooped > FPS) {
                        moveUpBln = false;
                        timesLooped = -1;

                    }
                    timesLooped++;
                }else{
                    isRunning = true;

                    characterModel.setY(characterModel.getY() + charMovementFPS);
                    if (timesLooped == FPS || timesLooped > FPS) {
                        executor.shutdownNow();
                        isRunning = false;
                    }
                    timesLooped++;
                }

            }

        }, 0, 3, TimeUnit.MILLISECONDS);

    }
}

注意:-1 不是问题,这是故意的

layoutslogcat 在说什么?我是否对我的非引擎游戏施加了太大的压力?

标签: javaandroidmultithreadingfreeze

解决方案


推荐阅读