7 Replies Latest reply on Apr 16, 2006 7:54 PM by icemansiva

    Sprite Movement

      Hi i was wondering if its possible to get a sprite to move accross the stage, then when clicked on it changes to a different sprite, plays a sound and resets to its original position to start over again?

      currently i have the sprite moving across the screen once, and the sprite i want to replace the original with appears in the center of the stage when i click, not where the first sprite was.

      on mouseup me

      Hopefully someone understands what i'm trying to do. Any help would be great

        • 1. Re: Sprite Movement
          James Newton, ACP Level 3
          property pSprite
          property pStartLoc
          property pTargetLoc
          property pStep
          property pFrames

          on beginSprite(me)
          pSprite = sprite(me.spriteNum)
          pStartLoc = pSprite.loc

          pTargetLoc = point(0, 0) -- or wherever
          pFrames = 30 -- number of frames to reach target

          pStep = (pStartLoc - pTargetLoc) / float(pFrames)

          on enterFrame(me)
          if not pFrames then
          end if

          pFrames = pFrames - 1

          vLoc = pTargetLoc + pFrames * pStep
          pSprite.loc = vLoc
          end enterFrame

          on mouseUp(me)
          pSprite.member = me.mGetMember()
          pSprite.loc = pStartLoc

          puppetSound(1, "MouseUp Sound")

          pFrames = 30

          on mGetMember(me)
          return pSprite.member -- or something more imaginative
          • 2. Re: Sprite Movement
            M4rkeh Level 1
            Thanks v much for the help openspark, i'll try this tonight, can i just ask what the difference is between -

            pSprite = sprite(me.spriteNum)
            pSprite = sprite the spritenum of me

            Is there two versions or a shorter version of lingo i'm missing out on. Sorry if this is a stupid question i'm new to director, just wondering why people on these forums usually type lingo in a way different to what i'm taught in class.
            • 3. Re: Sprite Movement
              James Newton, ACP Level 3
              'pSprite = sprite(me.spriteNum)' will not work in Director 6.5 and earlier, whereas 'pSprite = sprite the spritenum of me' will.

              In both cases, you can also use

              property spriteNum -- explicit declaration of the implicit spriteNum property

              on beginSprite
              pSprite = sprite(spriteNum)
              -- etc
              • 4. Re: Sprite Movement
                M4rkeh Level 1
                That script sort of does what i need it to do, i'm not sure if I fully understand what its doing though.
                Is there a way to get the sprite to return to the original location once it gets to the target location and has not been clicked on?
                Also can i get the sprite image to change to another image when its clicked on before it resets to the original location?

                • 5. Re: Sprite Movement
                  James Newton, ACP Level 3
                  In the enterFrame() handler, when pFrames reaches 0, it appears at the target point. Subsequently, the enterFrame() handler is shortcircuited. You could add code to allow pFrames to reach -1, and when it does so, return it to its pStartLoc.

                  You could move the line...

                  pSprite.member = me.mGetMember()

                  ... to a mouseDown() handler, so that the member changes on mouseDown, but the sprite moves back to pStartLoc on mouseUp.

                  You need to change the mGetMember() handler so that it returns a different member. I do not know what different member(s) you might want to use, so I have left this as 'an exercise for the reader'.
                  • 6. Re: Sprite Movement
                    M4rkeh Level 1
                    thanks for all the help openspark, i'm slowly getting things working
                    I still can't get the sprite to change though -
                    what do i do with mGetMember() ? put the sprite number between the brackets or sprite name?
                    Sorry one more question is there any way to set a random time before the sprite appears? such a wait or hold command set to a random interval before the sprite is shown on the stage?

                    apologies for all the questions i don't mean to be a pain in the rear

                    • 7. Re: Sprite Movement
                      Hi Guys, im new here, i want to know what actually these codes do in Lingo..

                      on mouseEnter
                      cursor 280
                      sprite (2).member = “red”

                      on mouseLeave
                      cursor –1
                      sprite (2).member = “black”

                      on mouseUp

                      on exitFrame me
                      sound playFile 1, “music/la_la_la_luv_song.mp3”
                      go to the frame

                      on mouseUp
                      puppetSound 1, 0