2
\$\begingroup\$

I'm developping a Tile base game where I have to generate transition tiles. To do so, I have a method that generate those tiles from 2 existing one and 1 "filter tile". I use this method to make a pixMap from the region I retrieved from my TextureAtlas.

public Pixmap getPixMapFromRegion(TextureRegion region){

    Texture texture = region.getTexture();
    TextureData data = texture.getTextureData();
    if (!data.isPrepared()) {
        data.prepare();
    }
    Pixmap pixmap = data.consumePixmap();
    int width = region.getRegionWidth();
    int height = region.getRegionHeight();
    Pixmap px = new Pixmap(width, height, Format.RGBA4444);
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            int colorInt = pixmap.getPixel(region.getRegionX() + x, region.getRegionY() + y);

        }
    }
    return px;
}

Them I apply this method

public Pixmap generateMixedTile(TiledMapTileSet tileset, AssetManager assMan,String template, TextureRegion region1, TextureRegion region2) {
    TextureAtlas atlas = assMan.get("../core/assets/tuiles/MergeFilter.atlas")
    AtlasRegion region = atlas.findRegion(template);
    Pixmap templ = getPixMapFromRegion(region);
    Pixmap img1 = getPixMapFromRegion(region1);
    Pixmap img2 = getPixMapFromRegion(region2);
    Pixmap res = newPixmap(region.getRegionWidth(),region.getRegionHeight(),Format.RGBA4444);

    for (int y = 0; y < templ.getHeight(); y++) {
        for (int x = 0; x < templ.getWidth(); x++) {
            if(0xFF000000 == templ.getPixel(x, y))
                res.drawPixel(x, y, img1.getPixel(x, y));
            else
                res.drawPixel(x, y, img2.getPixel(x, y));
        }
    }
    return res;
}

It seems that after asking again and again for the same texture in the AssetManager, I get a Couldn't load file ../core/assets/tuiles/Water3.png Exception. But this happen after the system success a lot of time to access that same file.

So I don't know how I could handle that because I thought that using assetManager and Atlas was the bests practices

Any Idea of how to fix that or to do it in another way?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I found out that it was a lack of memory that helped me to open the picture.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .