7 Replies Latest reply on Apr 28, 2008 11:37 AM by Armo_Director_user

    Button to move sprite

    Armo_Director_user
      I have a script on a graphic of a down arrow. When I click on the button, I want to move anoter sprite named "letter". The script works, but the repeat loop to keep moving the sprite while the mouse button is depressed - actis instantaneously. So instead of moving slowly, 5 pixels at a time, it moves about 200 pixels at once (this range is defined in the script, since the start postition of the sprite is 495 -- 495-295=200).

      Can someone let me know if there is code I can insert into the repeat loop to slow it down??

      LINGO CODE IS ATTACHED.

        • 1. Re: Button to move sprite
          Level 7
          You can try adding an updateStage() immediately after the line where you
          change the sprite location. Truth be told though, using a repeat loop
          in a situation like this is not the ideal way to do it, as it can
          prevent other code from executing until the loop completes.
          • 2. Re: Button to move sprite
            Armo_Director_user Level 1
            Thank you for the reply. Can you suggest a better way to have the sprite keep moving while the mouse button is depressed?

            Many thanks in advance!
            • 3. Re: Button to move sprite
              Level 7
              Put this on the sprite instead of your repeat loop. It will run on
              every enterFrame which will not lock out the other sprites.


              on enterFrame me
              if the mouseLoc.inside(sprite(me.spriteNum).rect) then
              if the mouseDown then
              if sprite("Armen_letter").locV > 295 then
              sprite("Armen_letter").loc = sprite("Armen_letter").loc - point (0,1)
              end if
              end if
              end if
              end
              • 4. Re: Button to move sprite
                Level 7
                Did the updateStage thing work for you? If using the repeat loop isn't
                causing you any problems, that may be just fine. You need to understand
                though that no other code can execute while the loop is running. That's
                the biggest problem. Also, using updateStage kind of changes the normal
                flow of how Director messages and events work. It is generally not
                recommended.

                The more conventional way is to move the sprite incrementally in
                response to exitFrame events. I have built a simple example of how you
                might do it. I am not the most advanced lingo programmer, so there may
                be an even better way. This is really just a starting point.

                ftp://v-fort.org/director/move.zip


                Armo_Director_user wrote:
                > Thank you for the reply. Can you suggest a better way to have the sprite keep moving while the mouse button is depressed?
                >
                > Many thanks in advance!
                • 6. Re: Button to move sprite
                  Armo_Director_user Level 1
                  Dave,
                  many thanks for all your help. It all works well now.

                  There is only one thing left that I need help with. There are 2 parts to this though.

                  One is that I can't seem to get lingo to execute 2 statements under a single "if" statement. Code is below. The "slider_ball" and "letter" sprites should move when the button sprite (where this code is attached) is pressed. Only the "letter" sprite moves though for some reason.

                  Also, is there a way to have the "slider_ball" sprite move 12 pixels lower for every 5 pixels the "letter" sprite moves?

                  MANY THANKS IN ADVANCE!! YOU ARE A HUGE HELP!

                  • 7. Re: Button to move sprite
                    Armo_Director_user Level 1
                    thanks for all the help again. I finally got it!