5 Replies Latest reply on Apr 15, 2009 7:35 PM by fazstp

    locH panning style - include a stop

      Hello

      My apologies if this has already been asked a million times, had a look but couldn't see anything.

      Anyway, I have a scene where when the user hovers the cursor right, and the background image moves left (giving the impression they are looking to the right of the room), and the same if they look left. I'll attach the lingo which I placed on each button here (tried it using the Attach Code button, but it didn't seem to work :S):

      left button:

      on mousewithin me
      sprite(1).locH=sprite(1).locH+13
      end

      Right Button:

      on mousewithin me
      sprite(1).locH=sprite(1).locH-13
      end

      My problem is that it keeps on going, even when the image is finished, so you are left with a blank screen. Anyone know how to include a stop, so that once it reaches a certain point, it wont go any further?

      I've noticed on different forums people have had the same problem, but I have tried to implement the solutions given but have had no luck.

      Cheers

      Graeme
        • 1. Re: locH panning style - include a stop
          Level 7
          graemekyuss wrote:
          > left button:
          >
          > on mousewithin me
          > sprite(1).locH=min(sprite(1).locH+13, theMaxValue)
          > end
          >
          > Right Button:
          >
          > on mousewithin me
          > sprite(1).locH=max(sprite(1).locH-13, theMinValue)
          > end

          where theMaxValue and theMinValue are variables you set, or simply numbers
          if that suffices.

          Andrew


          • 2. Re: locH panning style - include a stop
            robdillon Most Valuable Participant
            You probably want to stop the image just as it disappears off one edge of the stage or another. To do this, you need to know two thing, the width of the stage, and the width of the image to be moved.

            Normally a bitmap graphic's registration point is at its center. So you want the image to stop moving to the left when the locH is negative half it's width, and on the right when the locH is positive half it's width plus the width of the stage.

            So in code that would be something like:
            property stageWidth
            property halfWidth
            property leftEdge
            property rightEdge

            on startMovie
            stageWidth = _movie.stage.rect[3] - _movie.stage.rect[1]
            halfWidth = sprite(1).width/2
            leftEdge = halfWidth * -1
            rightEdge = stageWidth + halfWidth
            end

            on mouseWithin me
            if (sprite(1).locH + 13 > leftEdge) && (sprite(1).locH + 13 < rightEdge) then
            sprite(1).locH = sprite(1).locH + 13
            end if
            end
            1 person found this helpful
            • 3. Re: locH panning style - include a stop
              I've had a good play about but cannot solve this :S

              The stage width is 1000, and the image width is 2880 if that is any help?
              • 4. Re: locH panning style - include a stop
                robdillon Most Valuable Participant

                Try this:

                 

                property stageWidth
                property halfWidth
                property leftEdge
                property rightEdge
                property thisSprite

                on beginSprite me
                  thisSprite = me.spriteNum
                  stageWidth = _movie.stage.rect[3] - _movie.stage.rect[1]
                  halfWidth = sprite(thisSprite).width/2
                  leftEdge = halfWidth * -1
                  rightEdge = stageWidth + halfWidth
                end

                on mouseWithin me
                  if (sprite(thisSprite).locH + 13 < rightEdge) then
                    sprite(thisSprite).locH = sprite(1).locH + 13
                  end if
                end

                • 5. Re: locH panning style - include a stop
                  fazstp Level 2

                  Left button:

                   

                  on mouseWithin me

                  if ( sprite( 1 ).left >= 0 ) then

                  exit

                  end if

                   

                  if ( sprite( 1 ).left <= -13 ) then

                  sprite( 1 ).locH = sprite( 1 ).locH + 13

                   

                  else

                  sprite( 1 ).locH = sprite( 1 ).locH - sprite( 1 ).left

                  end if

                   

                  end mouseWithin

                   

                   

                  Right Button:

                   

                  on mouseWithin me

                  if ( sprite( 1 ).right <= _movie.stage.rect.width ) then

                  exit

                  end if

                   

                  if ( sprite( 1 ).right >= _movie.stage.rect.width + 13 ) then

                  sprite( 1 ).locH = sprite( 1 ).locH - 13

                   

                  else

                  sprite( 1 ).locH = sprite( 1 ).locH + _movie.stage.rect.width - sprite( 1 ).right

                  end if

                   

                  end mouseWithin

                  1 person found this helpful