Hello together,
following code:
public class PlayScreen implements Screen {
private ManaMain game;
private TextureAtlas atlas;
private OrthographicCamera gamecam;
private Viewport viewPort;
private Hud hud;
private WorldManager worldManager;
private OrthogonalTiledMapRenderer renderer;
private PathManager pathManager;
private KeyController keyController;
private Thread pathThread;
private RayHandler rayHandler;
private PointLight pLight;
public PlayScreen(ManaMain game) {
Assets.load();
Assets.manager.finishLoading();
this.atlas = Assets.manager.get(Assets.texture, TextureAtlas.class);
this.game = game;
this.gamecam = new OrthographicCamera();
this.hud = new Hud(game.batch);
this.viewPort = new FitViewport(ManaMain.V_WIDTH / ManaMain.PPM, ManaMain.V_HEIGHT / ManaMain.PPM, gamecam);
this.worldManager = new WorldManager(this);
this.keyController = new KeyController(worldManager.getPlayer(), true);
this.renderer = new OrthogonalTiledMapRenderer(worldManager.getMap(), 1 / ManaMain.PPM);
rayHandler = new RayHandler(worldManager.getWorld());
rayHandler.setAmbientLight(1f);
pLight = new PointLight(rayHandler, 20, Color.CYAN, 0.2f, 0 ,-0.5f);
//gamecam.position.set(viewPort.getWorldWidth() / 2, viewPort.getWorldHeight() / 2, 0);
gamecam.setToOrtho(false);
hud.setBox2DDebugRenderer();
pathManager = new PathManager(worldManager);
pathThread = new Thread(pathManager);
pathThread.start();
}
@Override
public void show() {}
------------------------------------------------------------------------------------------------------------------
private void cameraUpdate() {
Vector3 position = gamecam.position;
position.x = worldManager.getPlayer().getBody().getPosition().x;
position.y = worldManager.getPlayer().getBody().getPosition().y;
gamecam.position.set(position);
gamecam.update();
}
--------------------------------------------------------------------------------------------------------------------
public void update(float delta) {
rayHandler.update();
keyController.handleInput();
worldManager.update(delta);
// gamecam follows the player
cameraUpdate();
game.batch.setProjectionMatrix(gamecam.combined);
renderer.setView(gamecam);
}
@Override
public void render(float delta) {
update(delta);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// is rendering the game map
renderer.render(new int[] { 0 });
hud.renderDebugTable(keyController.isDebugMode(), worldManager.getPlayer());
hud.renderBox2DDebugShapes(keyController.isDebugMode(), worldManager.getWorld(), gamecam);
hud.renderAIPath(keyController.isDebugMode(), pathManager, gamecam);
game.batch.setProjectionMatrix(gamecam.combined);
game.batch.begin();
worldManager.draw(game.batch);
game.batch.end();
renderer.render(new int[] { 1 });
rayHandler.render();
worldManager.render();
game.batch.setProjectionMatrix(hud.getStage().getCamera().combined);
hud.getStage().draw();
}
@Override
public void resize(int width, int height) {
viewPort.update(width, height);
}
I hope its enough to understand my code. The cameraUpdate()-Method is maybe the problem. At the moment, when i move my player (worldManager.getPlayer()) the camera is following as i needed to ( cameraUpdate() shows it). But when i am using light, for example PointLight it is also following my player. I want something like campfire that obvious dont follow the player it has a fix point on map. How can i solve it?