11 Replies Latest reply on Dec 4, 2006 2:21 AM by duckets

    Help with scroll image

    Level 7
      Hello:
      I need to make a scroll of one image. I have two buttons (left and rigth)
      and I want that scroll slowly every time I push button must move 70 pixels.
      And let me use other elements on the stage like stop audio or so.
      I am trying but is impossible for me. Can you help me please?

      thank you very much


        • 1. Re: Help with scroll image
          duckets Level 1
          To scroll an image left or right, you simply need to increase or decrease the sprite's locH position.

          For example, this behaviour (attached below) placed on a sprite will allow you to move it to the left or right.

          - Ben
          • 2. Re: Help with scroll image
            duckets Level 1
            If you specifically want to scroll a certain distance each time (70 pixels), I would use something like this. The next 'destination' H value is stored in a variable, and updated when you press left or right. The sprite's loch is then altered by one pixel if it differs from the destination H value. There's also a check which prevents you from altering the destination H value again until it has finished scrolling. (code attached)

            hope this helps!

            - Ben
            • 3. Re: Help with scroll image
              Level 7
              Thank you very much:
              Ok. I have two buttons (left/right) when I use locH to move the sprite in 70
              pixels at a time I need that do it smoothly. But
              What I get is a quick jump.
              This is in my button

              global gMove

              on mouseUp me

              gMove=true

              end
              ---

              this is in Exitframe

              -------------------

              global gMove

              on exitFrame

              if gMovethen

              repeat with D=1 to 70

              sprite(1).loch=sprite(1).loch+1

              end repeat

              gMueve=false

              go to the frame

              end


              • 4. Re: Help with scroll image
                Level 7
                Thank you for your support:
                I'm not very well with this. And I don't know how to do this
                click on a button to move the image right slowly.


                "duckets" <webforumsuser@macromedia.com> escribió en el mensaje
                news:ekpcnm$21c$1@forums.macromedia.com...
                > If you specifically want to scroll a certain distance each time (70
                > pixels), I
                > would use something like this. The next 'destination' H value is stored in
                > a
                > variable, and updated when you press left or right. The sprite's loch is
                > then
                > altered by one pixel if it differs from the destination H value. There's
                > also a
                > check which prevents you from altering the destination H value again until
                > it
                > has finished scrolling. (code attached)
                >
                > hope this helps!
                >
                > - Ben
                >
                >
                > property my
                > property destinationH
                >
                > on beginSprite me
                > my = sprite(me.spritenum)
                > destinationH = my.locH
                > end
                >
                >
                > on exitFrame me
                >
                > if my.locH = destinationH then
                >
                > -- only read keyboard if we're not scrolling!
                > pLeft = keyPressed(123)
                > pRight = keyPressed(124)
                > destinationH = destinationH + (pRight - Pleft)*70
                >
                > else
                >
                > -- choose -1 or +1 for the scroll direction:
                > scrollDirection = (my.locH > destinationH) - (my.locH < destinationH)
                > my.locH = my.locH + scrollDirection
                >
                > end if
                >
                > end
                >


                • 5. Re: Help with scroll image
                  Level 7
                  Increase your frame rate of the movie to make the scroll smoother

                  --
                  Craig Wollman
                  Lingo Specialist
                  Word of Mouth Productions
                  212-928-9581

                  www.wordofmouthpros.com
                  "Anne" <anmalo42@lycos.es> wrote in message
                  news:ekpcud$279$1@forums.macromedia.com...
                  > Thank you very much:
                  > Ok. I have two buttons (left/right) when I use locH to move the sprite in
                  > 70 pixels at a time I need that do it smoothly. But
                  > What I get is a quick jump.
                  > This is in my button
                  >
                  > global gMove
                  >
                  > on mouseUp me
                  >
                  > gMove=true
                  >
                  > end
                  > ---
                  >
                  > this is in Exitframe
                  >
                  > -------------------
                  >
                  > global gMove
                  >
                  > on exitFrame
                  >
                  > if gMovethen
                  >
                  > repeat with D=1 to 70
                  >
                  > sprite(1).loch=sprite(1).loch+1
                  >
                  > end repeat
                  >
                  > gMueve=false
                  >
                  > go to the frame
                  >
                  > end
                  >
                  >


                  • 6. Re: Help with scroll image
                    Level 7
                    Thank you again.
                    Does not work.
                    I think that maybe easy to do it. Perhaps put a timer in anywhere?

                    "forum.macromedia.com" <lingoboy@wordofmo.com> escribió en el mensaje
                    news:ekpfpc$5eu$1@forums.macromedia.com...
                    > Increase your frame rate of the movie to make the scroll smoother
                    >
                    > --
                    > Craig Wollman
                    > Lingo Specialist
                    > Word of Mouth Productions
                    > 212-928-9581
                    >
                    > www.wordofmouthpros.com
                    > "Anne" <anmalo42@lycos.es> wrote in message
                    > news:ekpcud$279$1@forums.macromedia.com...
                    >> Thank you very much:
                    >> Ok. I have two buttons (left/right) when I use locH to move the sprite in
                    >> 70 pixels at a time I need that do it smoothly. But
                    >> What I get is a quick jump.
                    >> This is in my button
                    >>
                    >> global gMove
                    >>
                    >> on mouseUp me
                    >>
                    >> gMove=true
                    >>
                    >> end
                    >> ---
                    >>
                    >> this is in Exitframe
                    >>
                    >> -------------------
                    >>
                    >> global gMove
                    >>
                    >> on exitFrame
                    >>
                    >> if gMovethen
                    >>
                    >> repeat with D=1 to 70
                    >>
                    >> sprite(1).loch=sprite(1).loch+1
                    >>
                    >> end repeat
                    >>
                    >> gMueve=false
                    >>
                    >> go to the frame
                    >>
                    >> end
                    >>
                    >>
                    >
                    >


                    • 7. Re: Help with scroll image
                      duckets Level 1
                      Increasing your frame rate won't help because you're trying to do your movement within this repeat loop:

                      repeat with D=1 to 70
                      sprite(1).loch=sprite(1).loch+1
                      end repeat

                      That's not the right way to go about smooth scrolling, as you've discovered. It's doing a large jump because you don't see anything until the repeat loop has finished execting.

                      Here's a demo movie which uses the behaviour example I provided above (with a small bug fix, I confused left and right in one place!):

                      http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizontal

                      http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizontalSteps

                      hope this helps,

                      - Ben



                      • 8. Re: Help with scroll image
                        Level 7
                        thank you again.
                        http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizo
                        this is not working.


                        "duckets" <webforumsuser@macromedia.com> escribió en el mensaje
                        news:ekpiil$8os$1@forums.macromedia.com...
                        > Increasing your frame rate won't help because you're trying to do your
                        > movement
                        > within this repeat loop:
                        >
                        > repeat with D=1 to 70
                        > sprite(1).loch=sprite(1).loch+1
                        > end repeat
                        >
                        > That's not the right way to go about smooth scrolling, as you've
                        > discovered.
                        > It's doing a large jump because you don't see anything until the repeat
                        > loop
                        > has finished execting.
                        >
                        > Here's a demo movie which uses the behaviour example I provided above
                        > (with a
                        > small bug fix, I confused left and right in one place!):
                        >
                        >
                        > http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizo
                        > ntal
                        >
                        >
                        > http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizo
                        > ntalSteps
                        >
                        > hope this helps,
                        >
                        > - Ben
                        >
                        >
                        >
                        >
                        >


                        • 9. Help with scroll image
                          duckets Level 1
                          It looks like the linnks have spilled over onto the next line of your message. Perhaps because you're reading in a newsgroup rather than the web forum?

                          See the line ends with "scrolling/horizo", and the next line has "ntal" .... ?

                          Maybe it would help your newsreader client if I put brackets around the links...

                          < http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizontal >

                          < http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizontalSteps >

                          - Ben
                          • 10. Re: Help with scroll image
                            Level 7
                            thank you very much.
                            I almost get what I need but I have a problem After push the button one time
                            never works again. This is my code can you help me please?
                            thank you.

                            property my
                            property pCentralH
                            property pSpeed
                            global gMueve
                            global gNumDiapo
                            property pTotalDiapos

                            on beginSprite me
                            my = sprite(1)
                            pCentralH = my.locH
                            pSpeed=-5
                            pTotalDiapos=11
                            end


                            on exitFrame me
                            --put destinationH
                            if gMueve then
                            Muevediapo 2

                            end if

                            end
                            On Mouseup me
                            gMueve=true
                            end

                            On Muevediapo Numerodiapos
                            if (pCentralH - my.loch)<=(Numerodiapos*70)- gNumDiapo then

                            scrollDirection = pSpeed
                            my.locH = my.locH + scrollDirection

                            else
                            gMueve=false
                            end if

                            end
                            >
                            >


                            • 11. Re: Help with scroll image
                              duckets Level 1
                              quote:

                              Originally posted by: Newsgroup User
                              After push the button one time never works again. This is my code can you help me please?



                              Firstly, when you're using a behaviour, don't use sprite(1), use sprite(me.spritenum). This way, the behaviour will work if you ever need to move your sprite. This is a way, in programming, of saying "whichever sprite this behaviour is placed on".

                              Second, you need to try and debug your code. You probably dont have a clear idea of what numbers are actually passing through your variables. Try using the 'put' command to display the numbers being used by your variables. In the code attached below, I have added a line which uses 'put' to display what is being evaluated on each side of your 'if' statement. If you watch the results, you shoud see why your click behaviour only works once.

                              Hope this helps!