3 Replies Latest reply on Sep 4, 2007 1:54 AM by duckets

    set sprite.rect - strange behaviour

      I have this code fragment in an behaviour that is attached to a sprite of a text member, recleft and cVer are a variable and a constant that are used to change the rect.left and rect.top values to change the sprites position. Rect.right and rect.bottom are changed accordingly to make sure that the sprite maintains its original width and height on the stage.

      strange thing happens however: the rect.top and rect.bottom values are not set correctly. I don't understand this. What can be the reason for this?

      put recLeft
      put cVer
      put recLeft + psprite.width
      put cVer + psprite.height
      psprite.rect = rect (recLeft, cVer, recLeft + psprite.width, cVer + psprite.height)
      put psprite.rect

      the output is this:

      -- 353
      -- 480
      -- 401
      -- 547
      -- rect(353, 487, 401, 540)
        • 1. Re: set sprite.rect - strange behaviour
          McFazstp Level 1
          What box type do you have on the text member? It needs to be fixed or scrolling in order to set the height.

          If you just want to position the sprite you can just set the loc
          psprite.loc = point( rectLeft, cVer )

          and the height and width should be unchanged
          • 2. Re: set sprite.rect - strange behaviour
            JanvanC Level 1
            I solved it.

            I used adjustwidth in combination with fixedlinespace. For some reason the sprite.height equals 67 although the member.height is 53.
            The fix was simple: I have to use the member.height property instead of the sprite height property.

            I used rects instead of locs because I had to line out sprites with centered registration points.

            thanks for you reply

            • 3. Re: set sprite.rect - strange behaviour
              duckets Level 1
              It's also worth noting that a sprite's "rect" property can appear tobehave in a strange way: if you set, then check the rect before a stage update, the rect property will still have the old value, but the sprite's width, height & loc will have been adjusted to reflect the new rect value that you set.

              A sprite's 'rect' property, when read, seems to always return the "previously drawn" version of the sprite on stage (i.e. its rect at the moment of the previous stage update), wheras loch, locv, width, height, relate to director's current knowledge of what the sprite ought to look like at the moment of the *next* stage update.

              Fitting in to this, I see "setting the rect of a sprite" as a kind of alias or shortcut to setting the loch, locv, width and height
              properties - which is why you see that if you set a sprite's rect, all those other 'live' properties are updated immediately, but the sprite's actual 'rect' property doesn't get updated until the sprite is redrawn.

              I think this is a kind of confusing and unexpected behaviour when setting and then reading a property, but it does have some logic which can be useful once you understand what's going on.

              To put it very simply:

              * Reading the rect property will *always* give you the sprite's rect as it appeared at the last stage update.

              * Setting a sprite's rect property to a given rect 'r' will actually adjust the sprite's loch, locv, width and height, so that its rect will become equal to 'r' *after* the next stage update.

              - Ben