10 Replies Latest reply on Sep 22, 2006 6:00 PM by mirianam

    How to stop hitTest when . . .

    mirianam
      Hello
      I am having problems with this one.
      I am dragging a sprite over a vector line and checking to see if the sprite is over the "path" or not. The sprite is not constrained. This part is OK.
      I also have another sprite move up the stage and what I would like is that the hitTest no longer checks if my "man" sprite is within my "path" sprite. This only works if the mouse button is relaesed but not if the "man" sprite is still being dragged.
      It works while the mouse is still down if I go to another frame but I want to stay on this frame with the "man" no longer draggable.

      I hope I am making sense.

      Can anyone guide me on this one please.



        • 1. Re: How to stop hitTest when . . .
          Level 7
          Hi Mirianam,

          I'm not entirely clear about what is moving and what is intersecting
          what here. You have some sprites identified by their channel number and
          some identified by a name.

          I can see that sprite "man" is not sprite 8, but I'm not sure if it is
          sprite 3 or some other channel number.

          You have no end at the end of your beginsprite function. It will
          probably still run, but its bad practice. There are also a couple of
          end if statements at the bottom of the testPosition function. Is sprite
          "path" a flash sprite? If not, then hitTest() won't work. That's
          designed for tracking Flash sprites.

          You don't really need the first three lines of the testPosition function.

          the fourth line could be:

          if hitTest(sprite("path"),sprite("man").loc) = #background then beep

          The last line of that function is using the within keyword. This means
          that the sprite "man"'s rect has to be completely inside the rect of
          sprite 8. Sprite "man" must be able to fit completely inside the rect of
          sprite 8, otherwise this will fail. You may want to use the keyword
          intersects. It works much the same way but only requires that one sprite
          touch another, not be completely enveloped by the other.

          If you are testing for sprite "man" being within sprite 8 in the
          exitFrame function, then there's no need to call the function
          testPosition.

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/
          • 2. Re: How to stop hitTest when . . .
            mirianam Level 1
            Thank you Rob and sorry that I was not very clear.
            I have 3 sprites -
            sprite "path" which is sprite 8. This is a vetor, a squiggly line
            sprite "man"
            sprite "water"

            The idea is that the user drags the "man" sprite along the "path". The beeps are to indicate if the "man" has gone off the "path". (The user will only be allowed so many beeps before it's game over. I haven't yet done ths part)

            While the user is gragging the "man" up the "path" another sprite called "water" is animating up the stage. The user need to reach the top of the stage before they are overtaken by the "water" sprite. I did want to use within rather than intersects as I wanted to let the game continue until the "man" sprite was completely within the "water" sprite.

            • 3. Re: How to stop hitTest when . . .
              mirianam Level 1
              sorry pressed the wrong button on the computer before I finished the message

              Thank you Rob and sorry that I was not very clear.
              I have 3 sprites -
              sprite "path" which is sprite 8. This is a vetor, a squiggly line
              sprite "man"
              sprite "water"

              The idea is that the user drags the "man" sprite along the "path". The beeps are to indicate if the "man" has gone off the "path". (The user will only be allowed so many beeps before it's game over. I haven't yet done ths part)

              While the user is gragging the "man" up the "path" another sprite called "water" is animating up the stage. The user need to reach the top of the stage before they are overtaken by the "water" sprite. I did want to use within rather than intersects as I wanted to let the game continue until the "man" sprite was completely within the "water" sprite.

              When I change (8) to ('water") in this line
              if sprite("man").within(8) then
              I get error that Integer is expected so I have left it as 8



              Here is the script I have so far (thanks for your help)

              on beginSprite me
              sprite("man").loc = point(426, 408)
              sprite("man").moveableSprite = TRUE
              end

              on exitFrame me

              if sprite("man").within(8) then
              sprite("man").moveableSprite = FALSE
              -- go to "GameOver"

              end if

              if hitTest (sprite("path"), sprite("man").loc) = #background then beep

              if sprite("man").within(8) then sprite("man").moveableSprite = FALSE -- sprite 8 is "path" sptite

              end if


              end

              My problem is that sprite "man" can continue to be draged until the user lets go of the mouse when the "man" is within "water".

              The hitTest is working - no problem with that.

              I want testHit to stop when the sprite"man" is within sprite "water" (ie to stop the beeps ) in case the "man" is not on the "path" and I want the sprite "man" to no longer be draggable even if the user is still holding down the mouse button.
              I've looked at "stillDown" but am getting nowhere.

              Can you help me please.


              • 4. Re: How to stop hitTest when . . .
                Level 7
                I did a very simple moveablesprite test. I never use this property and
                so wasn't familiar with how it works.

                From your description, is sounds like you have a problem with where you
                are placing this code. If this code is attached as a behavior to the
                "man" sprite then when the moveableSprite property is turned to false,
                that sprite should move back to it's original loc, not stay at the loc
                where the moveableSprite property is turned off.

                Try something like this attached to the "man" sprite. Be sure that you
                are using a behavior script window and not a movie script window.

                ---------
                property thisSprite


                on beginSprite me
                thisSprite = me.spriteNum
                sprite(thisSprite).moveableSprite = true
                sprite(thisSprite).loc = point (426,408)
                end

                on exitFrame me
                if sprite(thisSprite).within(8) then
                -- I think you want the "water" sprite number here not the line
                sprite number
                sprite(thisSprite).moveableSprite = false
                end if

                if hitTest (sprite("path"), sprite(thisSprite).loc) = #background then
                beep
                if sprite(thisSprite).within("water" sprite number) then
                sprite(thisSprite).moveableSprite = false
                end if
                end
                ---------

                You should see sprite 8, the "man" sprite jump back to it's original loc
                when the moveableSprite property is turned off.

                --
                Rob
                _______
                Rob Dillon
                Adobe Community Expert
                http://www.ddg-designs.com
                412-243-9119

                http://www.macromedia.com/software/trial/
                • 5. Re: How to stop hitTest when . . .
                  mirianam Level 1
                  Thank you Rob
                  I have tried your script but I am having the same problem. In both your script and my script the "man" sprite becomes not draggable only if I let go of the mouse. If I continue to hold the mouse down as I am dragging( still dragging when "man" sprite is within "water" sprite) I can continue to drag. If I let go of the mouse and try to drag again if it is withing the "water" then yes I cannot drag. If it is not within the "water" of course I can drag again.

                  It seems that if I am holding the mouse down when the within happens, that it does not get executed till I release the mouse.

                  If I change from not draggable to go to another frame the code does execute when the within happens.

                  Sorry to ask again but can you help me with this one.
                  • 6. Re: How to stop hitTest when . . .
                    Level 7
                    I just tried an example that I made up and if I drag the moveable sprite
                    over another sprite that I'm testing with a within statement, it stops
                    being draggable immediately, while I still have the mouse down.

                    There is something that you are doing that's very different from what I
                    am doing, and I don't know what the difference is.

                    Here's the example that I made:
                    http://www.ddg-designs.com/downloads/within.zip

                    Take a look at this and see if you can find how your movie is different.

                    --
                    Rob
                    _______
                    Rob Dillon
                    Adobe Community Expert
                    http://www.ddg-designs.com
                    412-243-9119

                    http://www.macromedia.com/software/trial/
                    • 7. Re: How to stop hitTest when . . .
                      mirianam Level 1
                      Again thank you very much for your help.
                      The diference between the 2 is that on my one I didn't comment out this line in beginSprite handler - "sprite(thisSprite).loc = point (426,408)".
                      When it is commented out it works they way you say, if it's not commented out then it stops being draggable only on mouseUp!!! Very curious, don't you think.

                      But anyway I do not want the "man" sprite to return to its original positions but to stop being draggable at the point that the "within" occurs.

                      I know that you have given me a lot of your time already but I would really like to solve this one. Thank you again.
                      • 8. Re: How to stop hitTest when . . .
                        mirianam Level 1
                        Hi Rob
                        If you are curious, so I am very curious but otherwiseI have found another solution which is working OK for me (at the moment).
                        I would love to know the answer to this puzzle but only if you have time.
                        Thank you so very much for all your help.
                        mm
                        • 9. Re: How to stop hitTest when . . .
                          Level 7
                          In that case you'll need to add some code. Here's a simple drag control
                          behavior:

                          -------------
                          property thisSprite
                          property animateMe

                          on beginSprite me
                          thisSprite = me.spriteNum
                          animateMe = false
                          end

                          on mouseDown me
                          animateMe = true
                          end

                          on mouseUp me
                          animateMe = false
                          end

                          on mouseUpOutside me
                          animateMe = false
                          end

                          on exitFrame me
                          if anamateMe then
                          sprite(thisSprite).loc = the mouseLoc
                          end if
                          end
                          ---------------

                          You should be able to incorporate that into your existing code.

                          --
                          Rob
                          _______
                          Rob Dillon
                          Adobe Community Expert
                          http://www.ddg-designs.com
                          412-243-9119

                          http://www.macromedia.com/software/trial/
                          • 10. Re: How to stop hitTest when . . .
                            mirianam Level 1
                            Bingo!
                            Very nuch appreciated.Thanks