libgdx / box2dlights

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

Light attached to body not repositioning if body changes size #84

Closed adam-law closed 9 years ago

adam-law commented 9 years ago

As the titles states, the offsets for an attach light does not change when a body size is scaled up or down, causing the body to "eat" into the light area. If a texture is drawn in conjunction to a body's size and position, this means the texture would overlap the light.

It'd be nice if a light can auto-correct this, but adding methods to manipulate the light, such as the offset fields, could also work.

rinold commented 9 years ago

Oh, I see... box2lights is not tracking this currently. Despite of it also lacks the 'setOffset' methods you should be able to manipulate offset values by performing 're-attachment' to the same body with updated offset values. BTW, just to clarify the case, how exactly you are scaling the box2 body sizes?

adam-law commented 9 years ago

Thanks, and sorry for the late reply. I destroy the main fixture and recreate it. I took a brief look at the source and it seems box2dLights uses the Body for reference, and not its fixtures, so I thought it safe to do what I did.

I might have done it wrong, but IIRC, I did try re-attaching the light with different offsets, but it didn't seem to work. I'll try again.

rinold commented 9 years ago

Hmm.. From the draft look at the code, I haven't found how re-attaching might be not working. The one possibility is that the body position after resizing changes the same way as offset but with different sign and compensates your offset change. Can you check if the body position and/or if the fixture offset relatively to body changes during re-size? Also, how the behavior changes (it will not affect offsets but might affect "eating" issue) if you set the:

light.setIgnoreAttachedBody(true);
adam-law commented 9 years ago

okay, will do. btw, re-attachment does work, the light follows the body as it moves, it's just that it still seems to beam from its initial attachment point (I haven't tried again as I said above, however. I was a bit busy on something else.).

thanks.

adam-law commented 9 years ago

something must have gotten fixed in libgdx. I didn't amend anything but this works correctly now.