5 Replies Latest reply on Apr 11, 2010 12:33 PM by Sean_Wilson

    HELP! When foreground sprite moves over location change bkground sprite to picture

    Matthew Grandin

      Help!

       

      Im fairly new to director and need some urgent guidance or help.

       

       

      Basically I have setup a grid of squares four across four down.

       

      The squares are all seperate sprites 200 by 200 multi coloured.

       

      I created a transparent centered square sprite that moves directly over each square on the grid using the arrow keys:

       

      on exitFrame me

        go to the frame

        if the loch of sprite 18 > 800 then

          set the loch of sprite 18 to 100

        end if

        if the locv of sprite 18 > 800 then

          set the locv of sprite 18 to 100

        end if

        if the loch of sprite 18 < 0 then

          set the loch of sprite 18 to 700

        end if

        if the locv of sprite 18 < 0 then

          set the locv of sprite 18 to 700

        end if

       

      end


      on keydown me

        if the keycode = 126 then

          set the locv of sprite 18 to the locv of sprite 18 - 200

        end if

        if the keycode = 125 then

          set the locv of sprite 18 to the locv of sprite 18 + 200 

        end if

        if the keycode = 123 then

          set the loch of sprite 18 to the loch of sprite 18 - 200

        end if

        if the keycode = 124 then

          set the loch of sprite 18 to the loch of sprite 18 + 200

        end if

      end

       

       

       

      I want to write some script that changes whatever square the foreground highlighter sprite is over to a picture. It doesnt have to change back once its changed in the first instance I just want each square to change to a different picture when the sprite moved by the arrow keys moves over it.

       

      I thought this was going to be easy to eventually work out but its not at all! I initially tried using the preset behavious change cast member and alter the mouseover or whatever preset to 'if the loch of sprite 18 = 200 then' but no where near it.

       

      Can someone please help me out here iv spent days on this thought it would be easier than its turned out

       

       

      heres one of my atempts. pathetic i know:

       

                                         ---  if the loch of sprite 18 = 400 then

                                           ---    set the member of sprite 7 to member "PICTURE1"

                                           ---  end if 

       

       

       

      tha nks in advance cheers

        • 1. Re: HELP! When foreground sprite moves over location change bkground sprite to picture
          Sean_Wilson Adobe Community Professional

          I have taken the liberty of re-arranging your existing code a little - mostly to modernise the syntax away from the "old-school" 'set the property of object to value'. I have also cached some regularly referred to values into local variables to save typing and perhaps provide a minor performance boost:

           

          on exitFrame me
            
            spr = sprite(18)
            lH = spr.locH
            lV = spr.locV
            
            if ( lH > 800 ) then
              spr.loch = 100
            else if ( lH < 0 ) then
              spr.loch = 700
            end if
            
            if ( lV > 800 ) then
              spr.locv = 100
            else if ( lV < 0 ) then
              spr.locv = 700
            end if
            
            go to the frame
            
          end
          
          on keyDown me
            spr = sprite(18)
            case the keyCode of
              123: spr.loch = spr.loch - 200
              124: spr.loch = spr.loch + 200
              125: spr.locv = spr.locv + 200
              126: spr.locv = spr.locv - 200
            end case
          end
          

           

          It's not clear from your post whether the code you posted is a behavior script, and if so which sprite/channel it's associated with, or whether it's a movie script. I suspect the latter since graphic sprites aren't usually sent keyDown messages.

           

           

          As far as changing other sprites based on the location of your moveable sprite, are the BG sprites exactly the same size as the moveable sprite? Do you need your moveable sprite to simply touch a BG tile, or be completely enclosed within its boundaries?

           

          Since you are moving sprite 18 by increments of 200, and locking it to [0, 0, 800, 800], you might try the following modification to the above:

           

          on exitFrame me
            
            spr = sprite(18)
            lH = spr.locH
            lV = spr.locV
            
            if ( lH > 800 ) then
              spr.loch = 100
            else if ( lH < 0 ) then
              spr.loch = 700
            end if
            
            if ( lV > 800 ) then
              spr.locv = 100
            else if ( lV < 0 ) then
              spr.locv = 700
            end if
            
            go to the frame
            
          end
          
          
          on keyDown me
            spr = sprite(18)
            case the keyCode of
              123: spr.loch = spr.loch - 200
              124: spr.loch = spr.loch + 200
              125: spr.locv = spr.locv + 200
              126: spr.locv = spr.locv - 200
            end case
            
            tLoc = spr.loc
            case tLoc of
                -- adjust sprite numbers and member names to suit
              (point(100, 100)): sprite(2).member = member("picture1")
              (point(100, 300)): sprite(3).member = member("picture2")
              (point(100, 500)): sprite(4).member = member("picture3")
              (point(100, 700)): sprite(5).member = member("picture4")
                
              (point(300, 100)): sprite(6).member = member("picture5")
              (point(300, 300)): sprite(7).member = member("picture6")
              (point(300, 500)): sprite(8).member = member("picture7")
              (point(300, 700)): sprite(9).member = member("picture8")
                
              (point(500, 100)): sprite(10).member = member("picture9")
              (point(500, 300)): sprite(11).member = member("picture10")
              (point(500, 500)): sprite(12).member = member("picture11")
              (point(500, 700)): sprite(13).member = member("picture12")
                
              (point(700, 100)): sprite(14).member = member("picture13")
              (point(700, 300)): sprite(15).member = member("picture14")
              (point(700, 500)): sprite(16).member = member("picture15")
              (point(700, 700)): sprite(17).member = member("picture16")
            end case
          end
          
          • 2. Re: HELP! When foreground sprite moves over location change bkground sprite to picture
            Matthew Grandin Level 1

            Thanks for this this is exactly what im looking to do.

             

            Theres just a few slight niggels i with it.

             

            The pictures appear slightly off the stage when they appear and they look very bad quality compared to the original photos. any ideas?

             

            Thanks

            • 3. Re: HELP! When foreground sprite moves over location change bkground sprite to picture
              Sean_Wilson Adobe Community Professional

              Where the pictures appear is probably dictated by the location of their member.regPoint relative to the original image/tiles registration point.

               

              The quality I have no idea about - have you done a side-by-side comparison on the stage by just dragging members into an empty area of your score? That might tell you if the source is at fault or if it's something to do with re-sizing, or compression, or ...

              • 4. Re: HELP! When foreground sprite moves over location change bkground sprite to picture
                Matthew Grandin Level 1

                yeah i tried dragging them over to see what was going on but they appear perfect on the stage?

                 

                is there some way i can write lingo in the script to dictate where the regpoint for the cast members will be?

                 

                something like along the lines of member.regPoint ("picture1") = 100 or whatever it maybe

                 

                Sorry for my lack of knowledge iv only just started learning to use this application

                 

                thanks for your help

                • 5. Re: HELP! When foreground sprite moves over location change bkground sprite to picture
                  Sean_Wilson Adobe Community Professional

                  You can alter the registration point with code, or in the Paint window.

                   

                  Open your message window (Ctrl + M) and type:

                  member("picture1").regPoint = point(100, 100)

                  and press the ENTER key to execute this line of code.

                  You can query the regPoint of any member from the message window too:

                  put member("reference").regPoint
                  -- point(150, 150)
                  

                  or use the Property Inspector, set to List View Mode, with the Member tab active - regPoint is listed under the Graphic Properties and can be set from here too.

                  1 person found this helpful