8 Replies Latest reply on Jan 5, 2008 7:32 AM by FabM

    How to animate cast members after mouse events?

    FabM
      Hi there

      I´m doing a work for university using Director but i´m in need of help with it.

      What i want to do is to have animated cast members moving to a place in the stage after we press a button.

      For example, imagine a background photo of a stage (which will be my background image) and then image a wood crate image in the center of the stage.

      What i want to do is to press in that crate and after i pressed that crate 4 more wood crates will appear behyind the main crate and move to different points in the stage making it look like the five number in a dice.

      Can you help me with this?
        • 1. Re: How to animate cast members after mouse events?
          FabM Level 1
          Any kind soul that can help me with this?
          • 2. Re: How to animate cast members after mouse events?
            Lukewig Level 1
            Hi,

            Place the crates that appear when the middle one is clicked on the stage where you want them to appear (ie at the end point of the animaiton), and then add a behaviour like this to each of these sprites

            property mySprite
            property myOnLoc
            property myDestination
            property myCurrentLoc

            on beginSprite (me)

            -- grab a reference to the current sprite object
            mySprite = sprite(me.spriteNum)

            -- assume starts at the place it should appear
            -- when the center crate is clicked. So record it now
            myOnLoc = mySprite.loc

            -- now place the sprite off-screen
            myCurrentLoc = point(-999.0, -999.0)
            mySprite.loc = myCurrentLoc

            -- set this offscreen loc as the current destination
            -- (so we don't animate)
            myDestination = myCurrentLoc

            end


            on ShowCrates (me, fromPnt)
            if (fromPnt.ilk = #point) then myCurrentLoc = fromPnt
            mySprite.loc = myCurrentLoc
            myDestination = myOnLoc

            end

            on enterframe (me)

            -- if not at the destination loc, then move there
            if (myDestination = myOnLoc) then
            -- There are lots of ways of 'animating' to a point.
            -- This example simply moves halves the distance and
            -- then checks that the distance is not less 1 pixel
            -- (to prevent 'jiggling')
            dx = (myDestination.locH - myCurrentLoc.locH) / 2.0
            dy = (myDestination.locv - myCurrentLoc.locv) / 2.0
            myCurrentLoc = myCurrentLoc + point(dx, dy)
            if abs(dx) < 1 then myCurrentLoc.locH = myDestination.locH
            if abs(dy) < 1 then myCurrentLoc.locV = myDestination.locV

            mySprite.loc = myCurrentLoc
            end if
            end


            Now on the middle crate (the one that gets clicked) add a behaviour like this

            on mouseUp (me)

            sendAllSprites(#SHowCrates, sprite(me.spriteNum).loc)

            end


            Hope this helps,
            Luke
            • 3. Re: How to animate cast members after mouse events?
              FabM Level 1
              Thanks Luke, i will try to do what you wrote down but i still have some doubts about the code you gave me.

              I will see what i can do and keep you updated

              Cheers
              • 4. Re: How to animate cast members after mouse events?
                FabM Level 1
                Luke i´ve done what you told me but i´ve got an error when i start the movie.

                The error is this:

                **************************************************************************************
                "Script Error Property not Found

                dx = (myDestination.locH - myCurrentLoc.locH) / 2.0

                #locH
                **************************************************************************************

                When you tell me to grab a reference is it to give a name to the sprite and put it for example instead of mySprite i should put myLyrics, which is the name of the currente sprite?

                One thing i didn´t understand well is the fact that i should change the place where the sprite is when i´m typing the code or should i just dump the code into each of the sprites?
                • 5. Re: How to animate cast members after mouse events?
                  FabM Level 1
                  I´ve spoke with my teacher and he told me that i can also use the tweening function to this animation but i will still need a code right?

                  Like the OnMouseUp event in the sprite at the center and then the other sprites move in tweening to where i want? Is that correct?
                  • 6. Re: How to animate cast members after mouse events?
                    Lukewig Level 1
                    Hi,

                    The error your are getting is because some variable isn't being set. Remember, that code I posted should be in a script member of type #behaviour (then drag the behaviour on top of the sprites that are used for the crates).

                    > When you tell me to grab a reference is it to give a name to the
                    > sprite and put it for example instead of mySprite i should put
                    > myLyrics, which is the name of the currente sprite?

                    You don't need to change anything. Here's a barebones movie - hopefully it will make more sense:

                    http://www.lingoworkshop.com/downloads.examp73.dir

                    You are correct about tweening. You would replace the enterframe script with one that does the sort of 'tweening' you want.

                    -- Luke
                    • 7. How to animate cast members after mouse events?
                      FabM Level 1
                      I misunderstood you...i added a new script to each sprite and didn´t creat a new behaviour like you said.

                      Luke thanks, it´s working although there´s a box that doesn´t move, which is the one at the top left. I guess that sprite stays behind the central sprite.
                      • 8. Re: How to animate cast members after mouse events?
                        FabM Level 1
                        Ok, it´s working now.

                        Luke thank you very much for your help i´m really appreciatted

                        Cheers :)