this is a function for scaling up to a size while maintaining aspect
ratio that seems to work pretty well - i'm sure you can rework to scale down
on scaleSprite me,spriteToScale
-- updateStage
newW = pMemberToChangeTo.width
newH = pMemberToChangeTo.height
if pMemberToChangeTo.height>400 or pMemberToChangeTo.width > 774 then
perH =
float(pMemberToChangeTo.height-400)/float(pMemberToChangeTo.height)
perW = float(pMemberToChangeTo.width-774)/float(pMemberToChangeTo.width)
if perW>=perH then --use perW
newW = 774 --pMemberToChangeTo.width - (pMemberToChangeTo.width*perW)
newH = pMemberToChangeTo.height - (pMemberToChangeTo.width*perW)
else
newW = pMemberToChangeTo.width - (pMemberToChangeTo.width*perH)
newH = 400 --pMemberToChangeTo.height -
(pMemberToChangeTo.width*perH)
end if
end if
spriteToScale.width=newW
spriteToScale.height=newH
end
g r i m m w e r k s wrote:
>I've been trying to do this all sorts of ways and now my brain is locked.
>I'm sure once the answer comes back at me I'll feel like a dope. Thanks in
>advance for killing my self esteem.
>
>
>I've got a bunch of images that I need to scale to fit a maxWidth and
>maxHeight; trouble is these images are all sorts of possible dimensions.
>
>Say we want to fit a 320x240 area, if I request a rescaling for a rect of
>640x480, it will of course check for whether the requested rect is landscape
>or portrait, and scale it to meet the 320x240. This works fine for this:
>
>(taken from the handyman's digital portfolio at doug and changed slightly,
>whereas tMax and tMin are passed in):
>
>-- if tMem.width > tMem.height then
>-- newHeight = (tMem.height * pMax)/tMem.width
>-- offset = (pMax - newHeight)/2
>-- imRect = rect(0,0,pMax, newHeight)
>-- destRect = rect(0,0+offset, pMax, newHeight + offset)
>-- else
>-- newWidth = (tMem.width * pMin)/tMem.height
>-- offset = (pMin-newWidth)/2
>-- imRect = rect(0,0,newWidth, pMin)
>-- destRect = rect(0+offset, 0, newWidth + offset, pMin)
>-- end if
>
>
>but this really doesn't work, as the image passed in might not fit perfectly
>to a max/min -- it's really got to scale the image to fit whichever - the
>maxwidth or maxheight, no matter what the image dimensions are, ie:
>
>tPerc = (maxWidth/float(theRect.width)
>return(rect * tPerc)
>
>?
>
>[To remove yourself from this list, or to change to digest mode, go to
>http://www.penworks.com/lingo-l.cgi To post messages to the list, email
>[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
>learning and helping with programming Lingo. Thanks!]
>
>
>
--
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
m u t a n t
m e d i a > solutions for success
Evan Adelman | 917.916.7378 | 598 Broadway NY NY 10012
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> | www.mutantmedia.com
<http://www.mutantmedia.com>
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]