1 Reply Latest reply on Jan 3, 2008 10:15 PM by Lukewig

    OffSet command

    Level 7
      hello every one
      Could anyone give me a simple example of using offset command to place
      images or any sprites on stage in a row next to each other.
      I have seen using this command in complex tiles placing.
      A simpler example would help.
      Do I create a map first?


        • 1. Re: OffSet command
          Lukewig Level 1
          Offset use useful for moving rectangles. For example

          SomeRect = rect(10,10,200,100)

          if you want to move this rect 30 pixels to the right, you could do any of the following:

          NewRect = rect(SomeRect.left + 30, SomeRect.top, SomeRect.right+30, SomeRect.bottom)
          NewRect = SomeRect + rect(30,0,30,0)
          NewRect = SomeRect.offset(30,0)

          So "offset" is just the same as adding to the left & right and top & bottom of a rectangle

          If you want to move a sprite, usually you change the loc rather than the rect. For example

          SomeSprite.loc = SomeSprite.loc + point(30,0) -- moves the sprite 30px to the right

          You could do the same thing moving the rect

          SomeSprite.rect = SomeSprite. rect.offset(30,0) -- moves the sprite 30px to the right

          To answer your question about rows of sprites, if the sprites are different sizes, then I would do something like this (this assumes the sprites are in channel 1 to 10, and the first sprite is in the correct place

          repeat with i = 2 to 10
          SpriteOnLeft = sprite(i-1)
          L = SpriteOnLeft,right
          T = SpriteOnLeft.bottom + prite(i).height
          R = L + sprite(i).width
          B = SpriteOnLeft.bottom
          sprite(i).rect = rect(L,T,R,B)
          end repeat

          If the sprites were the same height (H) and width (W), then you could do it like this

          repeat with i = 2 to 10
          SpriteOnLeft = sprite(i-1)
          sprite(i).rect = SpriteOnLeft.rect.offset(W,0)
          end repeat

          -- Luke