Tinting a tile in LibGDX

Well, now I’m confused. I redid my code to look like this:

package com.nishu.particaletest;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.nishu.particaletest.entities.Tile;

public class GameScreen implements Screen {
	OrthographicCamera camera;
	SpriteBatch batch;
	Sprite sprite;

	Tile[][] tiles;

	int sWidth = ParticaleGame.getWIDTH();
	int sHeight = ParticaleGame.getHEIGHT();
	int width = sWidth / Tile.SIZE;
	int height = sHeight / Tile.SIZE;

	@Override
	public void show() {
		camera = new OrthographicCamera();
		camera.setToOrtho(false, ParticaleGame.getWIDTH(),
				ParticaleGame.getHEIGHT());
		batch = new SpriteBatch();
		tiles = new Tile[width][height + Tile.SIZE];

		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height + Tile.SIZE; y++) {
				tiles[x][y] = new Tile(x, y, false, false);
				System.out.println(tiles[x][y].getTile().getX() + " , " + tiles[x][y].getTile().getY());			
			}
		}
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0.2f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

		camera.update();
		batch.setProjectionMatrix(camera.combined);

		batch.begin();
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height + Tile.SIZE; y++) {
				//tiles[x][y].setPos(x, y);
				tiles[x][y].getTile().draw(batch);
				System.out.println("Render: " + tiles[x][y].getTile().getX() + " , " + tiles[x][y].getTile().getY());			
			}
		}
		batch.end();
	}

	@Override
	public void dispose() {
		batch.dispose();
	}

	@Override
	public void resize(int width, int height) {
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

	@Override
	public void hide() {

	}
}

The output for the rendering coords are this(it works, I’m only showing a section of it):

Render: 752.0 , 288.0
Render: 752.0 , 304.0
Render: 752.0 , 320.0
Render: 752.0 , 336.0
Render: 752.0 , 352.0
Render: 752.0 , 368.0
Render: 752.0 , 384.0

Yet, I still end up with a blank screen. Why?

Anyone? Please I’ve been stuck on this for days and it ridiculous.

Remember that when you use an orthographic camera, your origin is set to the center of the screen. Try to zoom the camera out [icode]camera.zoom = .5f;[/icode] to see if your tiles are just being rendered off screen.

I re-read the thread a few times… :-\ If you’re still having problems and would like help, pastebin or w/e your entire code, tell me what is going wrong and I will run it and have a go at fixing it as soon as I wake up

Ah! I love you this worked! Can you explain why though? If I set the zoom level to 0, I cannot see any tiles. Anything above 0, and it renders fine! I’m thinking that 0 means its fully zoomed in. Am I correct? Still, thank you so much!

Edit: also, I tried calling sprite.scroll and it did nothing. I increased the values of the scroll and then drew the tile, but it didn’t do anything. However, sprite.setColor worked fine. Why is it only some sprite functions seem to work? :confused:

Your zoom should automatically be set at 1 whenever you create an orthographic camera. Weren’t your tiles just off screen? Also, you should use [icode]camera.translate(x, y);[/icode] to make your sprites scroll.

I honestly have no idea what was wrong with my camera and tiles, this is my first foray into LibGDX. And ok that should work but why isn’t the sprite.scroll method working? I just don’t understand…

I’m sure scroll works fine…

Really not sure what bits of code we’re looking at now so I can’t help you at all, but

http://code.google.com/p/libgdx-users/wiki/ScrollingTexture

in particular,

spriteTexture.setWrap(!TextureWrap.Repeat, !TextureWrap.Repeat);

you tried that on your texture?

No I haven’t but I managed to get scrolling to work by just repositioning the camera, and it works great! Finally, all my problems are solved, thanks everyone!

I… well good work have fun with it… ::slight_smile:

Well, now I have to ask. Am I doing something wrong? :stuck_out_tongue:

Think just a misunderstanding about scroll, but if its working, ignore everything because thats all you need so no worries