我正在制作类似于汤姆游戏的游戏,其中角色在屏幕上进行动画处理并进行回访。
每个动画我有大约100个透明的PNG。 有10个动画。 每个PNG都被压缩到最大,最大文件大小为30KB。
我之前一直遇到内存管理方面的问题(修复它),但这是我之前尝试过的:
对我有用的是使用计时器,没有资产管理器,只需加载我需要的任何帧。 它在我家里的3款Android手机上工作得很好+朋友们,但他们都是现代三星& Nexus设备。 我还测试了一些仿真器,它的工作正常。
我几天前发布了游戏,我得到了一些关于游戏崩溃的评论,因为没有错误或日志报告,我不知道如何重现问题或调试它
这是我的Actor的代码,用于处理动画:
公共类AnimActor扩展了Actor {
private SpriteBatch batch;
private TextureAtlas textureAtlas;
private Sprite sprite;
private int currentFrame = 1;
private int TotalFrames ;
FileHandle[] filesxx;
String currentFolder;
Boolean currentLoop;
float stateTime;
TalkerGame Game;
AssetManager assets_manager;
String[] fileList;
TextureRegion tex1;
Texture tex = null;
Timer Timerx = null;
Timer.Task TheTask = null;
public AnimActor(TalkerGame talkerGame, AssetManager manager)
{
Game = talkerGame;
assets_manager = manager;
batch = new SpriteBatch();
sprite = new Sprite();
float scale = (float)( (float)Gdx.graphics.getWidth() / (float) (480));
sprite.setPosition(0, 0);
sprite.setBounds(0,0,(float)Gdx.graphics.getWidth() ,(float)Gdx.graphics.getHeight() );
// sprite.setScale(scale);
}
public void PlayAnimation(String FolderName,Boolean loop)
{
currentLoop = loop;
currentFolder = FolderName;
currentFrame = 1;
//String[] fileList = new String[0];
ArrayList<String> FileListArray = new ArrayList<String>();
final String Path = FolderName + "/";
filesxx = Gdx.files.internal(Path).list();
for (FileHandle file : filesxx) {
// do something interesting here
if( !file.name().contentEquals("icon.png") && file.name().contains(".png") )
{
FileListArray.add(file.name());
}
}
Collections.sort
(FileListArray, String.CASE_INSENSITIVE_ORDER);
fileList = FileListArray.toArray(new String[0]);
// Get all files in Folder
TotalFrames = fileList.length-1;
if(TheTask != null)
{
TheTask.cancel();
}
TheTask = new Timer.Task() {
@Override
public void run() {
currentFrame++;
if ((currentFrame > TotalFrames) && (currentLoop == false))
{
// Play Idle
PlayAnimation("idle", true);
currentLoop = true;
currentFolder = "idle";
// Stop Music if was playing
Game.StopMusic();
// Start/Restart Recording
Game.StartInterfaceRecord();
}
if ((currentFrame > TotalFrames) && (currentLoop == true))
{
currentFrame = 1;
}
/* if ((currentFrame > TotalFrames))
{
currentFrame = 1;
}*/
sprite.setRegion(getNextRegion(currentFrame));
}
};
if(Timerx != null)
{
Timerx.stop();
Timerx.clear();
}
Timerx = new Timer();
Timerx.schedule(TheTask, 0, 1 / 30.0f );
}
public TextureRegion getNextRegion(int CurrentFramex)
{
// System.gc();
String file_name = fileList[CurrentFramex]; // String.valueOf(CurrentFramex)+".png";
if(tex!=null)
{
// Game.aInterface.Log("Disposing Texture");
tex.dispose();
}
String num = "0";
if(CurrentFramex <10)
{
num = "00";
}
// System.gc();
FileHandle file = Gdx.files.internal(currentFolder+"/"+file_name);
tex = new Texture(file);
TextureRegion tex1= new TextureRegion(tex);
return tex1;
}
@Override
public void draw(Batch batch, float parentAlpha) {
// TODO Auto-generated method stub
sprite.draw(batch);
}
@Override
public void act(float delta) {
// TODO Auto-generated method stub
super.act(delta);
}
public String getCurrentFrameFile()
{
return currentFolder+"/"+fileList[currentFrame];
}
public void dispose(){
batch.dispose();
sprite.getTexture().dispose();
}
}
由于