On 16-jan-2006, at 15:51, Michael Nadel wrote:

This question has been plauging me for a long time and I'm sure there must be a simple answer. Is there a way to make a repeat loop to make a sprite grow and shrink in a way that will maintain proportions? In other words, it's easy to make a perfect box grow in size, but how do you make a rectangle grow and keep it's proportions while it grows? This is my code, but it doesn't work.

repeat while (mySprite.height < member(mySprite.member).height) and (mySprite.width < member(mySprite.member).width)
  mySprite.height = mySprite.height + 5
  mySprite.width = mySprite.width + 5
  updatestage
end repeat

You're adding the same amount to both height and width, this will distort the box.

The best way would be to multiply height and width with the same factor. However in order to do that you need to make sure that the factor by which you multiply will not be truncated to an integer. Use the float() function to prevent this.
Like this:

repeat while ...
        mySprite.height = mySprite.height * float(1.1)
        mySprite.width = mySprite.width * float(1.1)
end repeat

(i haven't actually tested this, you may even need to do:
mySprite.height = float(mySprite.height) * float(1.1)
etc.

This will enlarge the sprite 10% proportionally each repeat step.
Be aware that using a repeat loop for this will cause your routine to eat all available processor cycles. If you have other stuff going on at the same time, it's better to use the exitframe handler:

on exitFrame me
        if mySprite.height < mySprite.member.height then
                mySprite.height = mySprite.height * float(1.1)
                mySprite.width = mySprite.width * float(1.1)            
        end if
end

To make the sprite oscilate between large an small sizes, you have to add more code

Mark Hagers
[EMAIL PROTECTED]


[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!]

Reply via email to