LibGDX Flipping Problem [SOLVED]

The problem is because I hate to draw from bottom left corner and prefer top left corner, I did this,


cam.setToOrtho(true, Game.WIDTH, Game.HEIGHT);

But because of this, I need to flip every image. (I render each tile seperately) So I did this,


tile.flip(false, true);

But, the problem is this,

http://s4.postimg.org/uvbhqcty5/image.png

Every alternate tile is not getting flipped. Can anyone help ?
This is my first game using LibGDX. (Too used to Java)

What is “tile”? I guess the problem is, that you flip the reference “tile” for every new Tile on screen.
That means, that you flip the original tile, draw it, then you flip the allready flipped tile and draw that “double-flipped” tile.

Can you show the code where you rendered all the tiles? It would help alot. :wink:

I think I found an alternative to

tile.setFlip(false, true);

Try this:

tile.setRotation(540); // Flips it upside-down
tile.setOriginCenter(); // Keeps it in same position

If that doesn’t work, then it must be the way your rendering them.

The setRotation will not flip, but rotate it.
The difference is, that the flip will be only horizontal, while the rotation will be like a horizontal + vertical flip.
Also setRotation(540) should be the same as setRotation(180).
Also the setOriginCenter() should be called before rotating, i guess, as the rotation depends on the origin, which by default is the lower left corner.

I can’t do that because I am using TextureRegion.

Here’s my render code:


for (int row = rowOffset; row < rowOffset + numRowsToDraw; row++) {

			if (row >= numRows) break;

			for (int col = colOffset; col < colOffset + numColsToDraw; col++) {

				if (col >= numCols) break;

				 if (map[row][col] == 0) continue;

				int rc = map[row][col];
				int r = rc / numTilesAcross;
				int c = rc % numTilesAcross;

				TextureRegion tile = tiles[r][c].getImage();
				
				tile.flip(false, true);

				sb.draw(tile, (int) (x + col * tileSize), (int) (y + row * tileSize));
			}
		}

Use isFlipX() and isFlipY() before flipping. Your probably already flipping a flipped tile.

If not, then you need to flip every new instance of TextureRegion, so if you take a texture and split it into 4 regions, you have to flip all 4 regions.

It would help if you showed more code.

http://pastebin.java-gaming.org/675c4624f1014

Here’s my TileMap class and Tile class.

I fixed it. Looks like the problem was that I was flipping the flipped tile again.

Thanks guys !!! :slight_smile: :slight_smile: :slight_smile: :slight_smile:

Np!!! ;D