为什么我的FPS会下降?

时间:2013-01-20 18:29:53

标签: java android frame-rate

仅在单击对象并且需要从列表中删除时才会删除。 这是代码:

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 log:

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的副本,迭代真正的瓶子列表并将应删除的内容添加到另一个列表并从瓶子列表中删除该列表
  • Assets.burpSounds [burp]:burp是随机java mudle随机生成的局部变量。我删除了(打嗝是在构造函数中)它没有用...

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

正如我之前所说,当执行此代码块时 ONLY 会丢失。

1 个答案:

答案 0 :(得分:1)

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

编辑:为什么要在每次触摸时创建新的arraylist?不应该只是:

for( Bottle bottle : bottles ) {...}
相关问题