question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues scaling bodies along with their sprites

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
liabrucommented, Aug 10, 2019

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 applies Vertices.scale and updates the sprite scale simultaneously, rather than trying to figure out the scale factor.

1reaction
RichardPoole42commented, Jun 28, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sprite Scaling Problems (C++) - Cocos Forums
Hello. I just wanted to ask for help about my Sprite Scaling problems. I'm dealing with a strange problem when I started testing...
Read more >
Add sprite after scale also get scaled - cocos2d x
After that you can scale A, B independent and move them all with sprite C or scale whole human body with all your...
Read more >
150% Sprite Scale? | RPG Maker Forums
+50% scaling is the for pixels, scaling 50% never goes right. 100%, 200%, 300% are always better, scaling by 0.5x is manually editting...
Read more >
[Solved] image quality when scaling down for GM use
I've tried shrinking the images in Illustrator then exporting as png for spriter. There are 3 resolution settings for this. Low turns into ......
Read more >
Resize Sprites and Their PhysicsBo… - Apple Developer
Well, the problem is that if the sprites are the same physical size on different screens, then they have different amounts of space...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found