Please fix xScale and yScale with Box2D

Presently, setting an xScale or yScale attribute on an image, even if doing so before adding the image to Box2D via physics.addBody, results in the wrong bounding box being set by Box2D.

So, there are really two bugs to fix:

1. Box2D should be able to evaluate a Display Object's xScale and yScale properties during the invocation of physics.addBody, and scale the bounding box accordingly. This should be two lines of code at most.

2. Box2D should be able to intercept changes to a Display Object's xScale and yScale properties after the Display Object has been added as a physics body, and scale the bounding box accordingly.

Hit the same issue yesterday working on my first game with physics. This issue is listed on the physics docs, I do agree it would be a nice upgrade to support it. I ended up making new images that where the exact size for the physics sim.

An alternative is to create a bounding box based on the size of the image:

1
2
3
4
5
6
7
8
9
10
11
function getImageBoundingBox( image )
    xBound = ( image.width * image.xScale ) / 2
    yBound = ( image.height * image.yScale ) / 2
 
    return {
        -xBound, -yBound,
        xBound, -yBound,
        xBound, yBound,
        -xBound, yBound
    }
end
views:1371 update:2012/1/1 13:29:50
corona forums © 2003-2011