libgdx / box2dlights

Fork of box2dlights by Kalle Hamalainen
Apache License 2.0
256 stars 81 forks source link

FitViewport issue #41

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hello,

I have a problem with rendering my game with box2dlights and FitViewport option.

My project use gdxVersion = 1.5.3 and box2dlights:1.2 or 1.3.

I use macbook pro with Eclipse and test my game for Desktop.

I have a ortho camera and FitViewport:

my renderer create method:

...
camera = new OrthographicCamera(640, 320);
viewport = new FitViewport(640, 320, camera);
camera.position.set(camera.viewportWidth / 2f, camera.viewportHeight / 2f, 0);
camera.update();
...

my renderer render method:

camera.update();
....
batch.setProjectionMatrix(camera.combined);
....
rayHandler.setCombinedMatrix(camera.combined);
rayHandler.updateAndRender();

my resize() method:

renderer.getViewport().update(width, height);

renderer.getCamera().position.set(
                renderer.getCamera().viewportWidth / 2,
                renderer.getCamera().viewportHeight / 2, 0);

stage.getViewport().update(width, height, false);

after changing window size without using box2dlights my screen looks like this:

http://i59.tinypic.com/w12wb5.png

after changing windows size with box2dlights my screen looks like this:

http://i59.tinypic.com/2qmof3r.png

So it's looks like adding box2dlights disable correct work of FitViewport or i have a bug in my code.

I have no idea what is wrong with my code :(

rinold commented 9 years ago

Hi @postpunkpl,

It's not possible for v1.2, you should use the 1.3 - and the best way is to use the camera itself for setting combined matrix:

rayHandler.setCombinedMatrix(camera)

Also for the correct viewport rendering if not using default values you should set it manually (in resize method):

rayHandler.useCustomViewport(x, y, width, height);

Where the x, y, width and height are the values of your custom viewport.

ghost commented 9 years ago

Hi Mikhail!

Thank You very much! It works perfectly! :)

Greetings

Peter

rinold commented 9 years ago

You are welcome!

I will hold this issue open for a while, until the info on the Wiki will be created regarding the box2dlights custom viewport usage - it seems be quite useful, but missing currently.

ghost commented 9 years ago

Hello Mikhail,

I'm sorry to bother you, but i have again problem with FitViewports. Could you be so nice and look at this post?:

http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=18362&p=77183#p77183

Greetings

Peter

2015-02-09 16:44 GMT+01:00 Mikhail Churbanov notifications@github.com:

You are welcome!

I will hold this issue open for a while, until the info on the Wiki will be created regarding the box2dlights custom viewport usage - it seems be quite useful, but missing currently.

— Reply to this email directly or view it on GitHub https://github.com/libgdx/box2dlights/issues/41#issuecomment-73530464.

rinold commented 9 years ago

Added Wiki page