🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to position an object's X/Y properly when scaling for a zoom effect?

Started by
16 comments, last by SkipD 2 years, 5 months ago

@thaumaturge

Oh yeah i just wanna know how to set/correct the scale offset each loop. Cuz if i scale it wont position right; like a normal scale in the same position would make it look like its moving right and down. I wanna just subtract that change

Advertisement

Ah, I see--I think!

The thing is, you said that your images have their anchor at their centres, if I recall correctly--in which case when scaled they shouldn't appear to move.

So, if your images are moving, then where are their anchors?

I'm guessing that the anchors are at one of the corners. If so, then the adjustment to the position should just be by an amount of half the difference in each of width and height (possibly with a minus-sign before one or both of those, depending on which corner the anchor sits at), if I'm not much mistaken. Something like this:

xOffset = (newWidth - startWidth) / 2 // Or -(newWidth ...
yOffset = (newHeight - startHeight) / 2 // Or -(newHeight ...

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

@thaumaturge i cant thank you enough for the help here! Its like the last feature i wanna add to this project.

Tbh….i aint sure what the anchor even is…..lol i just thought to do like yer saying here where you just correct the offsets best u can sorta deal

I gather that you have it working, then? If so, then I'm glad, and further glad to have been of service. ^_^

(By “anchor”, I meant the point that the image treats as the position (0, 0)--its origin-point.)

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

@thaumaturge no i didnt get it working but im ever so thankful for the help; its the last thing until this project is complete

Ahhh i think its the upper left corner just like a normal image

Ah, I see!

In that case, I think that the “xOffset” value should be negative. The yOffset is still ambiguous, because it depends on whether the graphics -engine or -library that you're using has its zero-point at the top (and thus its y-values are negative) or at the bottom (and thus its y-values are positive). But you could simply try both and see which looks better.

Unless the formula that I gave you didn't work?

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

@thaumaturge i hadnt tried it yet, but i will do so soon and let u know how it works

This topic is closed to new replies.

Advertisement