Issues scaling bodies along with their sprites
See original GitHub issueI am scaling a body up by 1.5, and then back down to its original size. I’m doing this using a parametric animation, meaning I’m compounding the scale of the body until it exceeds a certain scale and then I stop the animation and set the scale to the target scale.
The problem is, I have to scale both the sprite and the actual body itself separately. The sprite has absolute xScale
and yScale
values which makes it easy to detect when the desired scale has been reached. The body does not have any such absolute value. The closest thing I’ve found is area
. At the end of the animation, I attempt to calculate the difference between the startingArea
and the currentArea
and determine a final value to scale the body by to reach the original size, but unfortunately it doesn’t work reliably.
Is there a way to access the absolute scale value of body? Am I missing something obvious?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top GitHub Comments
Exactly, there’s no concept of scale in the physics engine like there is with a rendering engine. The
Vertices.scale
function literally rescales the geometry in place, so you need to manage updating the sprite scale yourself. Probably the easiest way is to create a function that appliesVertices.scale
and updates the sprite scale simultaneously, rather than trying to figure out the scale factor.Body.scale doesn’t remember the original characteristics of the body; it just scales the vertices and adjusts the other properties of the body (mass, area, and so on) accordingly. So there is nothing obvious you’re missing; there just isn’t any such concept, internally, as the absolute scale of a body.
Having said that, using the area should work pretty well (not necessarily exactly, of course, as nothing is exact in a floating-point world) so it would be interesting to know how that is failing to work for you, especially if there’s some particular situation or shape of body that makes it fail.