我的简单应用程序受到framedrop的影响。我认为这是由于我的渲染方法:
public void draw(Canvas canvas) {
drawBackground(canvas);
drawPlayer(canvas);
drawEnemy(canvas);
}
正如你所看到的,每次调用此方法时都会绘制背景,以及玩家和敌人...“drawBackground(canvas)”看起来有点像这样:
public void paintBackground(Canvas canvas) {
canvas.drawBitmap(background, 0, 0, null);
}
drawPlayer和drawEnemy在我的玩家/或敌人对象返回的位置绘制圆圈。
有没有更好的解决方案来显示背景,播放器和其他对象,而不经常重绘它们?
logcat的:
02-14 17:30:11.904: D/dalvikvm(17783): GC_FOR_ALLOC freed 29K, 1% free 9069K/9132K, paused 17ms, total 18ms
02-14 17:30:11.912: I/dalvikvm-heap(17783): Grow heap (frag case) to 12.404MB for 3686416-byte allocation
02-14 17:30:11.927: D/dalvikvm(17783): GC_FOR_ALLOC freed <1K, 1% free 12669K/12736K, paused 20ms, total 20ms
02-14 17:30:12.341: D/dalvikvm(17783): GC_FOR_ALLOC freed 16K, 1% free 12696K/12748K, paused 24ms, total 24ms
02-14 17:30:12.349: I/dalvikvm-heap(17783): Grow heap (frag case) to 15.945MB for 3686416-byte allocation
02-14 17:30:12.373: D/dalvikvm(17783): GC_FOR_ALLOC freed <1K, 1% free 16296K/16352K, paused 24ms, total 24ms
02-14 17:30:12.560: D/OpenGLRenderer(17783): Enabling debug mode 0
02-14 17:30:18.045: D/dalvikvm(17783): GC_FOR_ALLOC freed 218K, 2% free 16377K/16632K, paused 20ms, total 20ms
02-14 17:30:18.052: I/dalvikvm-heap(17783): Grow heap (frag case) to 19.541MB for 3686416-byte allocation
02-14 17:30:18.076: D/dalvikvm(17783): GC_FOR_ALLOC freed 6K, 2% free 19971K/20236K, paused 21ms, total 22ms
02-14 17:30:28.529: D/dalvikvm(17783): GC_FOR_ALLOC freed 3899K, 20% free 16395K/20332K, paused 19ms, total 19ms
02-14 17:30:28.537: I/dalvikvm-heap(17783): Grow heap (frag case) to 19.557MB for 3686416-byte allocation
02-14 17:30:28.560: D/dalvikvm(17783): GC_FOR_ALLOC freed <1K, 2% free 19995K/20332K, paused 18ms, total 18ms
02-14 17:30:49.756: D/dalvikvm(17783): GC_FOR_ALLOC freed 4050K, 20% free 16464K/20552K, paused 20ms, total 34ms
02-14 17:30:49.763: I/dalvikvm-heap(17783): Grow heap (frag case) to 19.625MB for 3686416-byte allocation
02-14 17:30:49.779: D/dalvikvm(17783): GC_FOR_ALLOC freed 6K, 3% free 20057K/20552K, paused 21ms, total 21ms
02-14 17:30:57.107: D/dalvikvm(17783): GC_FOR_ALLOC freed 3938K, 21% free 16373K/20552K, paused 17ms, total 17ms
02-14 17:30:57.107: I/dalvikvm-heap(17783): Grow heap (frag case) to 19.536MB for 3686416-byte allocation
02-14 17:30:57.138: D/dalvikvm(17783): GC_FOR_ALLOC freed 14K, 3% free 19958K/20552K, paused 13ms, total 13ms
02-14 17:31:03.310: D/dalvikvm(17783): GC_FOR_ALLOC freed 3824K, 21% free 16370K/20552K, paused 31ms, total 31ms
02-14 17:31:03.310: I/dalvikvm-heap(17783): Grow heap (frag case) to 19.533MB for 3686416-byte allocation
02-14 17:31:03.381: D/dalvikvm(17783): GC_FOR_ALLOC freed 7K, 3% free 19962K/20552K, paused 30ms, total 30ms
02-14 17:33:31.943: D/dalvikvm(17783): GC_FOR_ALLOC freed 6253K, 27% free 17352K/23640K, paused 37ms, total 39ms
提前致谢