Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding rayhandler in LibGDx causes issues in InputListener #110

Closed
maneeshbhunwal123 opened this issue Jan 28, 2018 · 5 comments
Closed

Comments

@maneeshbhunwal123
Copy link

I am trying out Libgdx, and I have an actor which performs some action whenever we click on it. So far it is working fine. Now I want to add light to the actor. After doing some research I came across Box2DLights. When I tried adding it to my project onClick Actor which was working fine does not seem to work. I am pretty sure this is due to rayhandler/Box2DLights because that is the only change I am making. here is the minimal change that I made to include Box2DLights.

public class GameScreen implements Screen {
    private RayHandler rayHandler;
    private World world;

    public GameScreen(Game game) {
        this.game = game;
        world = new World(new Vector2(0, 0), true);
        rayHandler = new RayHandler(world);
        rayHandler.setAmbientLight(0.1f, 0.1f, 0.1f, 1f);
        rayHandler.setBlurNum(3);
    }

     @Override
    public void show() {
        viewport = new FitViewport(1080, 720);
        stage = new Stage(viewport);
        rayHandler.setCombinedMatrix(stage.getCamera().combined);
        Gdx.input.setInputProcessor(stage);
    }
    @Override
    public void render(float delta) {
        //some custom rendering logic, but nothing related to rayHandler, excluding this for brevity.
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act(Gdx.graphics.getDeltaTime());
        stage.draw();
        rayHandler.updateAndRender();
    }

Now When I debugged, I realised the the onClick is

working little below the actual actor
, that means somehow the coordinates sifted(I know weird). Can you please help?
I also asked this question here on stackoverflow
https://stackoverflow.com/q/48488569/4239538

@rinold
Copy link
Contributor

rinold commented Jan 28, 2018

The updateAndRender method can cause the reset of viewport to default one - thus your FitViewport breaks, so if your are setting in it show(), for custom viewports add use of the:
rayHandler.useCustomViewport(x, y, width, height);

A few more details are on this Wiki page.

@rinold rinold closed this as completed Jan 28, 2018
@maneeshbhunwal123
Copy link
Author

@rinold Thanks for your quick response, I tried

@Override
    public void show() {
        viewport = new FitViewport(1080, 720);
        stage = new Stage(viewport);
        rayHandler.useCustomViewport(0, 0, 1080, 720);
}

But this also is not working? Can you please help, what these values should be, if not these?

Thank you very much.

@rinold rinold reopened this Jan 28, 2018
@rinold
Copy link
Contributor

rinold commented Jan 28, 2018

Try using the viewport you create, may be it's different from the 1080x720 - e.g. like so:

viewport = new FitViewport(1080, 720);
rayHandler.useCustomViewport(viewport.getScreenX(),
                             viewport.getScreenY(),
                             viewport.getScreenWidth(),
                             viewport.getScreenHeight());

@maneeshbhunwal123
Copy link
Author

Thanks @rinold , saved my day.

@rinold
Copy link
Contributor

rinold commented Jan 28, 2018

Have a nice day! :)

@rinold rinold closed this as completed Jan 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants