6
\$\begingroup\$

Sorry for the bad title. I didn't know how else to explain it.

The following is a portion of my code:

public class AssetLoader {

    public static TextureAtlas spriteSheet;

    public static TextureRegion hill, hillTop, hillBottom, rabbitJumped, background1, background2, water, spikes, playButtonDown, playButtonUp, dust;

    public static void load() {
        spriteSheet = new TextureAtlas(Gdx.files.internal("data/SpriteSheet.txt"));

        background1 = spriteSheet.findRegion("background");
        background2 = spriteSheet.findRegion("background");


        TextureRegion[] runFrames = {spriteSheet.findRegion("Frame01"), spriteSheet.findRegion("Frame02"), spriteSheet.findRegion("Frame03"),
                spriteSheet.findRegion("Frame04"), spriteSheet.findRegion("Frame05"), spriteSheet.findRegion("Frame06"),
                spriteSheet.findRegion("Frame07"), spriteSheet.findRegion("Frame08"), spriteSheet.findRegion("Frame09"),  };

        runningAnimation = new Animation(.03f, runFrames);
        runningAnimation.setPlayMode(Animation.PlayMode.LOOP);


        background2.flip(true, false);

    }
}

For some reason, the texture Region background1 is also flipped. Any help would be appreciated.

Some irrelevant code was ommitted.

\$\endgroup\$
0

1 Answer 1

8
\$\begingroup\$

TextureAtlas#findRegion(String) returns a region with a name that matches the name specified. It does not copy the region, therefore any changes you make to the region will be reflected in the TextureAtlas.

To overcome this issue, simply instantiate a new TextureRegion object and pass it the region found inside your TextureAtlas:

background1 = new TextureRegion(spriteSheet.findRegion("background"));
background2 = new TextureRegion(spriteSheet.findRegion("background"));
\$\endgroup\$
0

You must log in to answer this question.

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