android - very large background textures -
for game i'm developing must use large background images. these images around 5000x3000. when attempting display single texture black boxes in gwt , android. created class splits image grid of textures:
public class largeimage extends loadablegroup { private boolean smooth=true; public string filename; private int truewidth,trueheight; private arraylist<image> tiles=new arraylist<image>(); private arraylist<texture> textures=new arraylist<texture>(); private final int maxtexturesize = 512; public largeimage(string filename, callbackassetmanager manager) { super(); this.filename=filename; pixmapparameter param=new pixmapparameter(); param.format=pixmap.format.rgba8888; addasset(new assetdescriptor(filename, pixmap.class,param)); manager.add(this); } public largeimage(pixmap map, boolean smooth) { super(); this.smooth=smooth; frompixmap(map); } public void loaded(callbackassetmanager manager) { if(!manager.isloaded(filename)) { gdx.app.log("load error",filename); return; } pixmap source = manager.get(filename, pixmap.class); frompixmap(source); } private void frompixmap(pixmap source) { (int x = 0;x < source.getwidth(); x+=maxtexturesize) { (int y = 0;y < source.getheight(); y+=maxtexturesize) { pixmap p = new pixmap(maxtexturesize, maxtexturesize, pixmap.format.rgba8888); p.drawpixmap(source, 0, 0, x, y, maxtexturesize, maxtexturesize); texture t=new texture(new pixmaptexturedata(p, pixmap.format.rgba8888, true, false, true)); textures.add(t); if(smooth) t.setfilter(texture.texturefilter.mipmaplinearnearest, texture.texturefilter.linear); uncoloredimage tile = new uncoloredimage(t); tile.settouchable(touchable.disabled); tile.setx(x); tile.sety(source.getheight()-y-tile.getheight()); p.dispose(); this.addactor(tile); tiles.add(tile); } } super.setwidth(source.getwidth()); super.setheight(source.getheight()); truewidth=source.getwidth(); trueheight=source.getheight(); } @override public void setwidth(float width) { setscalex(width/truewidth); super.setwidth(math.abs(width)); } public void setheight(float height) { setscaley(height / (float)trueheight); super.setheight(math.abs(height)); } @override public void dispose(callbackassetmanager m) { super.dispose(m); for(int i=0;i<textures.size();i++) textures.get(i).dispose(); } }
the issue comes when need load other levels. after 6 loads gl out or memory errors. keeping reference each texture create , dispose of when loading new level. how come running out of memory though dispose old textures?
maybe have make dispose part "source":
pixmap source = manager.get(filename, pixmap.class); frompixmap(source);
maybe you.if not use more
Comments
Post a Comment