我的应用程序有些问题。有时会出现卡顿的情况,并显示“GC_CONCURRENT freed”的信息。我使用MAT工具查看了消耗大量内存的原因,发现一个对象列表占用了很多内存。问题在于我的游戏中有方块,我需要确定玩家是否踩在它们上面,所以我使用了这个列表。目前我有200个方块,但我将拥有更多,我不认为它们应该使用这么多内存,我该怎么办来解决这个问题?这是方块类的代码:
package com.NeverMind.DontFall.android;
import android.util.Log;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
/**
* Created by user on 20-Aug-15.
*/
public class blockClass {
private SpriteBatch spriteBatch;
public float x, y, sizeX = 100, sizeY = 100, startTime;
private boolean isTouched = false;
private Texture texture;
Sprite blockSprite;
public blockClass(float sentX, float sentY, Texture sentTexture, float scaleX, float scaleY){
x = sentX;
y = sentY;
sizeY *= scaleY;
sizeX *= scaleX;
spriteBatch = new SpriteBatch();
texture = sentTexture;
blockSprite = new Sprite(texture);
startTime = System.currentTimeMillis();
}
public void draw(float cameraX, float cameraY) {
spriteBatch.begin();
spriteBatch.draw(blockSprite, x + cameraX, y + cameraY, sizeX, sizeY);
spriteBatch.end();
}
public void update(float posX, float posY, boolean immune){
if (isTouched == false && immune == false)
if (touched(posX, posY) )
isTouched = true;
if (isTouched == true) {
y -= 10;
}
}
public boolean touched (float posX, float posY)
{
if (posX >= x && posX < x + sizeX && posY == y + sizeY)
return true;
return false;
}
public boolean toKill (float posY){
if (isTouched && y < posY - 1000)
return true;
return false;
}
}