gpt4 book ai didi

java - 为什么我的 FPS 下降?

转载 作者:行者123 更新时间:2023-11-30 03:49:10 27 4
gpt4 key购买 nike

只有当对象被点击并且需要从列表中移除时它才会掉落。这是代码:

if(event.type == TouchEvent.TOUCH_DOWN){
for(Bottle bottle : new ArrayList<Bottle>(bottles)){
if(bottle.position.dist(touchPoint) < 40 ){
bottles.remove(bottle);
if(bottle.type == Bottle.BOTTLE){
score+=10;
Assets.playSound(Assets.beeropenSound);
}
else if (bottle.type == Bottle.BOTTLE30){
score+=30;
Assets.playSound(Assets.beeropenSound);
}
else if (bottle.type == Bottle.GLASS_OF_BEER){
score+=5;
Assets.playSound(Assets.pourbeerSound);
}
else if (bottle.type == Bottle.WATER_BOTTLE){
score-=50;
}

// burping
if (score % 200 == 0 && score > 1){
Assets.playSound(Assets.burpSounds[burp]);
}
break;
}
}

,这里是 fps 日志:

01-20 19:18:19.629: D/FPS(27501):  59
01-20 19:18:20.639: D/FPS(27501): 59
01-20 19:18:21.639: D/FPS(27501): 49
01-20 19:18:22.649: D/FPS(27501): 59
01-20 19:18:23.669: D/FPS(27501): 60
01-20 19:18:24.669: D/FPS(27501): 59
01-20 19:18:25.689: D/FPS(27501): 60
01-20 19:18:26.699: D/FPS(27501): 43
01-20 19:18:27.719: D/FPS(27501): 60
01-20 19:18:28.739: D/FPS(27501): 60
01-20 19:18:29.759: D/FPS(27501): 60

我尝试删除这些东西,但不是这样:

  • 删除音效
  • 删除流媒体背景音乐(3mb mp3 文件)
  • 删除 ArrayList 的副本,迭代真实的 bottles 列表并将应删除的内容添加到另一个列表,然后从 bottles 列表中删除该列表
  • Assets.burpSounds[burp]:burp 是使用 Random java mudle 随机生成的局部变量。我删除了它(打嗝在构造函数中)它没有用......

还剩下一件事——垃圾收集器。这是什么让我的 fps 下降?我怎么能确定?如何对抗这些敌人?

正如我之前所说,它在执行此代码块时掉线。

最佳答案

我认为也是 GC,我会在 bottles 列表上添加一个标志,告诉对象它已“删除”而不是实际删除它,从而避免 gc。

编辑:为什么要在每次触摸时创建一个新的数组列表?不应该只是:

for( Bottle bottle : bottles ) {...}

关于java - 为什么我的 FPS 下降?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14427772/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com