Ох .. да, я уже вроде как решил это, прочитав этот вопрос:
Невозможно получить Box2dLigh ...
Используя этот пост, я заставил их работать, но теперь они появляются только в 0,0 объекта, что выглядит странно
Тень отбрасывается не в ту позицию
Вот мой класс экрана:
private Handler handler;
//Graphics
private OrthographicCamera camera;
private OrthogonalTiledMapRenderer renderer;
private static final int viewportWidth = 768;
private static final int viewportHeight = 768;
// Create a separate camera for box2dlights
OrthographicCamera b2dCam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
//World
private RoomStage stage;
private World world;
private RayHandler rayHandler;
//Creatures
private Player player;
//Game
private int level = 0;
private FPSLogger fps;
public GameScreen(Handler handler) {
this.handler = handler;
}
//METHODS
@Override
public void show() {
fps = new FPSLogger();
handler.setLevel(level);
//Graphics
camera = new OrthographicCamera(viewportWidth, viewportHeight);
camera.setToOrtho(true, viewportWidth, viewportHeight);
camera.position.set(0, viewportHeight / 2f, 0);
camera.update();
ScreenViewport viewport = new ScreenViewport(camera);
//Box2d
world = new World(new Vector2(0f, 0f), false);
handler.setWorld(world);
RayHandler.useDiffuseLight(false);
RayHandler.setGammaCorrection(false);
rayHandler = new RayHandler(world);
rayHandler.setWorld(world);
rayHandler.setAmbientLight(new Color(0f, 0f, 0f, 0.02f));
rayHandler.setBlurNum(5);
handler.setRayHandler(rayHandler);
b2dCam.setToOrtho(true);
b2dCam.update();
stage = new RoomStage(handler, viewport, "start");
handler.setStage(stage);
Gdx.input.setInputProcessor(stage);
stage.loadRoom();
//Creatures
player = new Player(handler, 12.5f * Global.PPM, 1f * Global.PPM);
stage.addActor(player);
stage.setKeyboardFocus(player);
renderer = new OrthogonalTiledMapRenderer(stage.getMap());
}
@Override
public void render(float delta) {
update(Gdx.graphics.getDeltaTime());
//Clear and Update
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
b2dCam.update();
//Render
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.setView(camera);
int[] backgroundLayers = new int[] {0, 1};
int[] foregroundLayers = new int[] {2, 3};
renderer.render(backgroundLayers);
stage.draw();
renderer.render(foregroundLayers);
rayHandler.setCombinedMatrix(b2dCam.combined.scale(Global.PPM, Global.PPM, Global.PPM), b2dCam.position.x / Global.PPM + 0.5f, b2dCam.position.y / Global.PPM + 0.5f, b2dCam.viewportWidth * b2dCam.zoom, b2dCam.viewportHeight * b2dCam.zoom);
rayHandler.updateAndRender();
fps.log();
}
public void update(float delta) {
stage.act(Gdx.graphics.getDeltaTime());
world.step(1 / 60f, 6, 2);
rayHandler.update();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
rayHandler.dispose();
world.dispose();
stage.dispose();
}
//Getters
public int getLevel() {
return level;
}
public World getWorld() {
return world;
}
//Setters
public void setLevel(int level) {
this.level = level;
}
Кроме того, вот мои динамические / статические тела
private void createBody() {
BodyDef def = new BodyDef();
def.type = BodyDef.BodyType.StaticBody;
def.position.set(getX() / Global.PPM, getY() / Global.PPM);
def.fixedRotation = true;
body = handler.getWorld().createBody(def);
PolygonShape shape = new PolygonShape();
shape.setAsBox(getWidth() / 2 / Global.PPM, getHeight() / 2 / Global.PPM, new Vector2(0.5f, 0.5f), 0);
body.createFixture(shape, 0.0f);
shape.dispose();
}
private Body createBody() {
BodyDef def = new BodyDef();
def.type = BodyDef.BodyType.DynamicBody;
def.position.set(getX() / Global.PPM, getY() / Global.PPM);
def.fixedRotation = false;
body = handler.getWorld().createBody(def);
body.setLinearDamping(10f);
PolygonShape shape = new PolygonShape();
shape.setAsBox(getWidth() / 2 / Global.PPM, getHeight() / 2 / Global.PPM);
body.createFixture(shape, 0.0f);
shape.dispose();
return body;
}
Огни больше не получают * Global.PPM (который равен 32):
pl = new PointLight(handler.getRayHandler(), 100, color, 12, x, y);
Если действительно буду признателен за вашу помощь!