开发者

Math related: How do I get a different scale if the value is less than one or greater than one

开发者 https://www.devze.com 2023-03-26 14:37 出处:网络
This should be an easy to solve but my brain has been fried the last few days. I have a slider that zooms in and zooms out a image. I want to zoom into the pixel level and zoom out to the pixel level

This should be an easy to solve but my brain has been fried the last few days. I have a slider that zooms in and zooms out a image. I want to zoom into the pixel level and zoom out to the pixel level but I have to have the thumbnail button be centered in the slider for a scale of 1.

What I have now is,

In code: // if the scale value is 1 the image is shown at original size var scale:Number = zoomSlider.value/1000; sprite.scaleX = sprite.scaleY = scale;

I set the default value to 5000 so that the button is centered in the middle but that sets the scale to 5. What I want is when I drag left (from the initial value of 5000) it should start to scale down until it gets to the minimum scale of .10. When I drag right it should start to increase the scale to 10.

The key to this question is that I have to have the th开发者_如何学编程umbnail button centered in the middle of the slider and when centered the scale is 1.


If you want the scale for 0 to 10,000 (since you specified center to be 5000) as above, then use

var scale:Number = zoomSlider.value/5000; 
sprite.scaleX    = sprite.scaleY = scale;

Whatever be the Scale, To keep the Scale Button centered and Image scaled to 1, set the 'scale' variable to 1/2 of the max Scale value.

0

精彩评论

暂无评论...
验证码 换一张
取 消