2dengine / love.scene

Small scene graph library written for the LÖVE framework using pure Lua
MIT License
14 stars 1 forks source link

Great framework just a few questions? #1

Open deckarep opened 1 year ago

deckarep commented 1 year ago

Hello,

I recently found your love.scene framework and was hoping you can guide in me in a direction to solving an issue.

My issue is that when I have a sprite placed on a view that is scaled up by some factor...say sx=2, sy=2 so the sprite is doubled in size. How would I go about getting the sprites size relative to the scaled operation?

In other words: if I call setGraphic with an img of say 100x100 pixels does this framework have a way to report the dimensions as 200x200 given that a scale of double was done?

It would be cool if there existed a method to get the dimensions of the sprite after factoring in all the transforms applied. Or perhaps I'm thinking about this incorrectly.

Great api, I'm hoping I could leverage this at some point in a project i'm working on.

2dengine commented 1 year ago

Hello Sir and thank you for using the love.scene library. I have considered the option of calculating the bounding boxes of sprites automatically, this is trivial with Textures, Quads and Text. Mesh and ParticleSystem objects do not have a "getDimensions" function like the other Drawable objects and calculating their dimensions automatically is not efficient. If you want to measure the dimensions of a sprite as they appear on the screen we use:

-- convert to screen coordinates
cx, cy = sprite:localToScreen(0, 0) -- center
rx, ry = sprite:localToScreen(radius, 0) -- radius
-- find the distance between the two points
dx = rx - cx
dy = ry - cy
real_radius = math.sqrt(dx*dx + dy*dy) -- Pythagorean

If your script uses cameras it is a little more involved, but the principle is the same: convert two points to screen coordinates and find the distance between them.