java - 游戏冻结并显示连续执行 6 个布局。跳过
问题描述
好的,所以我已经尝试在没有游戏引擎的 2D 纯 android中平滑跳跃一周了。我现在正在使用ScheduledThreadPoolExecutor
。
所以我有一个名为 FPS 的变量。这是角色在达到 180 Y 值之前必须上升多少次;
注意:FPS
在整个游戏中并不是真正的每秒帧数。
当FPS
设置为 45 时,应用程序永远不会死机(除非我反复向跳转按钮发送垃圾邮件)
但是在 90 上,当我玩游戏时,游戏会冻结,logcat 会显示:
E/WindowManager: Performed 6 layouts in a row. Skipping
我使用什么(例如:Handler
Runnable
和Thread
),应用程序并不重要
下面是跳转代码:
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 不是问题,这是故意的
layouts
logcat 在说什么?我是否对我的非引擎游戏施加了太大的压力?
解决方案
推荐阅读
- angular - RouteReuseStrategy 多个具有不同状态的相同路由
- java - 看不到从 html 生成的 pdf 上的图像
- javascript - React Edit 值未绑定在动态输入选择中
- spring-cloud-gateway - Spring Cloud Gateway 限速器性能
- c++ - 我可以在使用 C++14 编译的项目中使用使用 C++17 编译的静态库吗?
- javascript - 尝试在 Vue 应用程序中更新 Chart.js 中的图表数据时出现意外错误
- html - 我想做类似三角形的旋转木马,但是怎么做?
- typescript - 没有重载匹配此调用。在 Typescript 中使用 Object reduce 回调时
- javascript - 开玩笑上传文件
- javascript - 使用 javascript / node js 从中间替换数字