Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

Box2DLight position seems to Floor

$
0
0

I am creating a top down game and i’m using raycasted lights from Box2Dlights, My light is all set up and working. its attached to the player’s Body, and when the player moves, the sprite I attached to the position moves fluidly, but the light’s position is jerky and lags behind the player, as if I was using the floored the position of the player and so it was only moving on whole numbers.

I create the coneLight like this:

public Box2DConeLightComponent(RayHandler rayH, Color color, float distance){
    light = new ConeLight(rayH, 4, color, distance, 0f, 0f, 0f, 45f);
    //increasing the rays beyond 4 does nothing
    light.setDistance(distance);//10
    light.setColor(color);//white
    light.setActive(true);
    light.setSoft(true);
    light.setSoftnessLength(distance);
}

Update the Light like this:

public void setPosition(Vector2 position){
    light.setPosition(position);//the position is player.getBody().getPosition()
}

Or I attach it to the player’s Body(i’ve tried both):

public void attachToBody(Body attachment) {
    light.attachToBody(attachment);
}

and to start this all off I begin by initializing the lighting like this:

public void initLighting(){
    /** BOX2D LIGHT STUFF BEGIN */
    RayHandler.setGammaCorrection(true);
    RayHandler.useDiffuseLight(true);
    rayH = new RayHandler(gWorld);
    rayH.setAmbientLight(0.5f, 0.5f, 0.5f, 0f);
    rayH.setCulling(true);
    rayH.setBlur(false);
    rayH.setBlurNum(2);
    rayH.setCulling(false);
    rayH.setShadows(true);
}

Does anyone know why this is happening?


Viewing all articles
Browse latest Browse all 434

Trending Articles