3 Replies Latest reply on Sep 27, 2006 9:58 AM by duckets

    Member Fills Sprite

    redneon
      I have a sprite on my stage which I'm applying numerous members to via the following line of Lingo:

      sprite(8).member = member(TempList["image"], "Graphics")

      The problem is that the member fills the sprite completely. The sprite has a width of 242 and a height of 257 but the members that I'm assigning to the sprite are all kinds of ratios. What I'm wanting to do is centre these members in the sprite but keep their ratio so that there are borders at top and bottom or left and right depending on the ratio of the image.
        • 1. Re: Member Fills Sprite
          Jamaux Level 1
          Have you tried testing a simpler version first. I would start by swapping members using the message window, ie put a member on the stage at sprite(8) and then in the message window try something like:
          sprite(8).member = member("anotherimage")
          updateStage
          If you have set the sprite(8) background to transparent and have not stretched the sprite on the stage, it should swap nicely, especially if your registration points in all the members are in the centre of the member. This usually works for me. Hope you get it resolved. Good luck.
          • 2. Re: Member Fills Sprite
            Level 7
            The results can vary depending on if the initial sprite in the score is
            scaled ( the stretch property is on) if not scaled one would expect the
            switched in member to retain it's original dimensions.

            The last resort approach may be to read the dimensions of the new
            member (member(x).rect, using these dimensions to alter the dimensions
            of the sprite.


            your fitting? to the original sprite box?

            One can compare the member width and height to the target rect width and
            height using te smaller ratio as a scaling factor applied to both width
            and height.
            • 3. Re: Member Fills Sprite
              duckets Level 1


              You need to determine if your current member's width to height ratio is greater or smaller

              than your target box's width/height ratio.

              Something like this:

              --------------------------------------------------
              original = member("original member")
              newMember = member("new image")

              targetRatio = float(original.height) / float(original.width)
              thisRatio = float(newMember.height) / float(newMember.width)

              mySprite.member = newMember

              if thisRatio < targetRatio then
              -- this image is proportionally narrower than the target box, so use full height
              mySprite.height = originalHeight
              mySprite.width = originalHeight * thisRatio
              else
              -- this image is proportionally wider than the target box, so use full width
              mySprite.width = originalWidth
              mySprite.height = originalHeight / thisRatio
              end if
              --------------------------------------------------
              Hope this helps!

              - Ben