[LibGDX] [Solved] Can't Move camera when using viewport?

So I’m using a viewport to stretch the game to fit into any android device, but now I can’t seem to move the camera at all. The camera’s width is 640 and the height is 480. For some reason the bottom left corner of the camera is stuck at -640 and I cannot figure out how to move it from there. Setting the camera’s position to anything will not move it at all. So pretty much I have a background the same size as the camera, the bottom left point of the background is positioned at {0, 0} but that happens to be the center of my camera that I can’t seem to move.


	public void show() {
		//Technical Stuff
		cam = new OrthographicCamera(640, 480);
		cam.setToOrtho(true, 640, 480);
		viewport = new StretchViewport(640, 480, cam);
		viewport.setScreenX(640);
		viewport.setScreenY(480);
		viewport.apply(true);
		cam.position.set(640, 480, 0);
		
		// Technical Graphical Stuff
		batch = new SpriteBatch();
		BackGroundTexture = new Texture(Gdx.files.internal("data/BackGround.png"));
		
		//World Graphics Stuff
		starField = new StarField();
		
		
		
		
	}

	@Override
	public void render(float delta) {
		update(delta);
		cam.update();
		
		batch.setProjectionMatrix(cam.projection);
		batch.begin();
		batch.draw(BackGroundTexture, 0, 0);
		starField.render(batch);
		batch.end();
		
		
	}
	
	public void update(float delta){
		
	}

	@Override
	public void resize(int width, int height) {
		viewport.update(width, height);
		
	}

P.S. It scaled correctly, so at least that’s working. Hopefullying this can be fixed or else I’m going to have to start using whacky coordinates.

Solved:

Changed the Batch’s projection matrix to camera.combined instead of camera.project.
Does anyone know what project would be used for?

Camera.project() is used to turn world coords into screen coords… I’m sure i’m not using the correct terminology here but that’s basically what it does.

For example: Say you want to drag something from your UI into your game, well the coord system is different so the placement would be weird. You would unproject the position and then place the item at that position. I’ve never used project, but I assume it’s the opposite way around. So you drag something from the world to the screen coords instead. Someone please correct me if i’m wrong :point:

If you are talking about cam.projection, that’s your projection matrix, ie. orthographic for 2D that simply converts the usual coordinate system from -1 to 1 to the dimension in pixels.

Ah yeah, there is the projection and then there is the project() method. I forgot about that :point: