我的应用程序出现了一些问题。有时它滞后,并给我“GC_CONCURRENT释放”。我使用MAT来查看消耗这么多内存的东西,并且我发现对象列表吃掉了很多内存。问题在于我的游戏中有块,我需要看看我的玩家是否踩在他们身上,这就是为什么我使用这个列表。我目前有200块,但我会有更多,我不认为他们应该使用这么多的内存,我能做些什么来解决这个问题?这是块类的样子:Android Studio Libgdx内存问题
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;
}
}
在开始游戏或运行时,您何时创建200块? –
它是一个全局变量,因此列表在游戏开始时创建,但只有一次。在列表创建后,我将其中的对象放在create()方法中,该方法只运行一次。 –
游戏渲染时,你是否会杀死对象? –