[LibGDX] Camera

Hello,

Can someone tell me why my map is not rendering in the full camera view?

My code:

package Module;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.loaders.TileAtlasLoader;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.tiled.TileAtlas;
import com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer;
import com.badlogic.gdx.graphics.g2d.tiled.TiledLoader;
import com.badlogic.gdx.graphics.g2d.tiled.TiledMap;
import com.badlogic.gdx.math.Vector3;

/**
 * 
 * @author Celes Eternal
 *
 */

public class Map {

	/*
	 * Data
	 * 
	 */
	
	//Block size
	static final int BLOCK_WIDTH = 32;
	static final int BLOCK_HEIGHT = 32;
	
	//class data
	private TileMapRenderer tileMapRenderer;
    private TiledMap map;
    private TileAtlas atlas;
    private OrthographicCamera cam;
 

    public Map(){
    	// Load the tmx file into map
    	map = TiledLoader.createMap(Gdx.files.internal("data/testMap.tmx"));

    	// Load the tiles into atlas
    	atlas = new TileAtlas(map, Gdx.files.internal("data/"));

    	// Create the renderer
    	tileMapRenderer = new TileMapRenderer(map, atlas,32, 32, 5, 5);
    	
    	//initialize
    	
    	cam = new OrthographicCamera(Gdx.graphics.getWidth(),
				Gdx.graphics.getHeight());
 
		cam.position.set(0, 0, 0);
		//cam.translate(Gdx.graphics.getWidth() / -2, Gdx.graphics.getHeight() / -2);
    	
    }
    
    public void render() {
    	cam.zoom = 1f;
    	cam.update();
    	
		tileMapRenderer.getProjectionMatrix().set(cam.combined);
		
		Vector3 tmp = new Vector3();
		tmp.set(0, 0, 0);
		cam.unproject(tmp);
		
		tileMapRenderer.render( tmp.x, tmp.y,
				Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	}
}

Thanks

ps : sorry for my english

So you create a new topic for the problem, and then go ahead and reply on your old one? logic sense makes.


cam.zoom = 1f;

is useless, the camera will be automatically set to a value, you don’t need to set the zoom every frame when its not changing, you only need to change the zoom when it is actually changing.

Your map may be too big for your screen, so you need to move the camera around the world to see it all.

try changing the values in


new OrthographicCamera(Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());

this can also have a effect (i think, changed some values for mine in a sample i was playing around with to learn LibGDX)

I replied for said thanks ^^
Fo the zoom, i know, it’s just because i wanted to put off this without //
I’ll try it after class, thanks

I’have tried some combinations but nothing work.

Why?

For me :

cam = new OrthographicCamera(Gdx.graphics.getWidth() ,
				Gdx.graphics.getHeight() );
 
		cam.position.set(0, 0, 0);

Make a camera who start at 0,0,0 and do my all screen , that isn’t?

And :

tileMapRenderer.getProjectionMatrix().set(cam.combined);
		
		Vector3 tmp = new Vector3();
		tmp.set(0, 0, 0);
		cam.unproject(tmp);
		
		tileMapRenderer.render( tmp.x, tmp.y,
				Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

Make me a MapRenderer which take the whole screen too, no?

I had this problem. You should just pass the camera into the render() mathod


tiledMapRenderer.render(cam);

Libgdx has also changed their tilemap API. Be sure to get the latesst nightly package of libgdx. Read the api here.

Sorry i’m late,
my problem was just that the origin’s camera is in the middle of graphics, i was thinking that it was the same but a friend give me this idea and he was right!

But yes use render(cam) is one of solution’s parts
Thanks