我正在一个libgdx项目上,从屏幕上触发了一个扩展actor的动画对象,它对于少于50帧的动画效果很好,但是当我尝试使用更多的帧数初始化我的动画对象时,应用程序崩溃,并且如果我重新运行该应用程序崩溃的动画,则会显示以下错误消息,我曾经尝试处置过图集。这是我正在使用的动画类。
public class AnimatedFullScreen extends Actor {
public boolean startAnimation = true;
public Sound sound;
private OnAnimationComplete mOnAnimationCompleterListener;
private Animation<TextureRegion> animation;
private TextureAtlas atlas;
private float scaleX, scaleY;
private float px = 0, py = 0;
private float animationWidth, animationHeight;
private int type = 0;
private float showTime;
private boolean loop;public AnimatedFullScreen(String atlasName) {
atlas = new TextureAtlas(Gdx.files.internal("animations/sceneatlas/"+atlasName+"/"+atlasName+".atlas"));
this.animation = new Animation<TextureRegion>(0.2f / 10f, atlas.getRegions());
this.scaleX = CommonObjects.screenWidth / atlas.getRegions().get(0).getRegionWidth();
this.scaleY = CommonObjects.screenHeight / atlas.getRegions().get(0).getRegionHeight();
this.loop = false;
this.px = 0;
this.py = 0;
this.startAnimation = true;
this.type = 0;
this.animationWidth =CommonObjects.screenWidth ;
this.animationHeight = CommonObjects.screenHeight;
}
@Override
public void act(float delta) {
super.act(delta);
showTime += delta;
}
@Override
public void draw(Batch batch, float parentAlpha) {
if (startAnimation) {
batch.draw(animation.getKeyFrame(showTime, loop), px, py, 0, 0,
type == 0 ? animation.getKeyFrame(showTime).getRegionWidth() : animationWidth,
type == 0 ? animation.getKeyFrame(showTime).getRegionHeight() : animationHeight,
type == 0 ? scaleX : scaleY,
type == 0 ? scaleY : scaleY, 0);
}
//shows still image when animation not started
else {
batch.draw(animation.getKeyFrame(0, loop), px, py, 0, 0,
type == 0 ? animation.getKeyFrame(showTime).getRegionWidth() : animationWidth,
type == 0 ? animation.getKeyFrame(showTime).getRegionHeight() : animationHeight,
type == 0 ? scaleX : scaleY,
type == 0 ? scaleY : scaleY, 0);
}
//fires listener when animation completed
if (animation.isAnimationFinished(showTime)) {
if (mOnAnimationCompleterListener != null) {
atlas.dispose();
Gdx.app.log("ssa","ddss");
mOnAnimationCompleterListener.setNextScreen();
}
}
}
public void setListener(OnAnimationComplete listener) {
mOnAnimationCompleterListener = listener;
}}
这是错误日志
07-11 11:51:10.209 28389-28485 /? W / Adreno-GSL :: sharedmem_gpumem_alloc:mmap失败errno 12内存不足 07-11 11:51:10.233 28389-28485 /? E / Adreno-GSL :: GSL MEM错误:kgsl_sharedmem_alloc ioctl失败。
答案 0 :(得分:0)
libGDX中的动画允许的帧数没有技术限制。唯一的限制是内存。因此,如果遇到内存分配错误,则总体上会有太多的对象。您应该考虑优化动画以减少帧数,或优化所涉及的精灵以降低内存。同时检查所有其他正在使用的图形,以查看是否可以优化图形。您没有提到是否存在,但是如果没有,请确保使用精灵表来帮助使用内存。尽量减少浪费的空间,以降低内存使用量。