2 Replies Latest reply on Apr 20, 2013 11:11 AM by anjemalo

    Drag horizontally

    anjemalo Level 1

      Hello:

      I need to drag an image only horizontally. Can you tell me wich is the best and simplest way to do it?

      have you any sample or demo?.

       

      Thank you very much

        • 1. Re: Drag horizontally
          CopyPixels

          Here is a behavior that will restrict dragging to Horizontal or Vertical.

           

          --  Drag sprite Vertically or Horizontally

           

          property  sp  -- this sprite

          property  pDirection  -- the direction to constain dragging,  #Horizontal, #Vertical

          property  pStartLoc  --  sprite location upon mouseDown

          property  pMouseStart  -- mouse location upon mouseDown

          property  pMoving  -- flag for enterFrame. True/False

           

           

          On GetPropertyDescriptionList me

            Props = [:]

            Props[#pDirection] = [#default:#Horizontal, #format:#symbol, #Range:[#Horizontal, #Vertical], #comment:"Pick direction to drag"]

            return Props

          end GetPropertyDescriptionList

           

           

          on beginSprite me

            sp = sprite(me.spriteNum)

            pMoving = false

          end beginSprite

           

           

          on mouseDown me

            pStartLoc = sp.loc

            pMouseStart = _mouse.mouseLoc

            pMoving = true

          end mouseDown

           

           

          on mouseUp me

            pMoving = false

          end

           

           

          on mouseUpoutside me

            pMoving = false

          end

           

           

          on enterFrame me

            if not pMoving then exit

           

            deltaMouse = _mouse.mouseLoc - pMouseStart

           

            if pDirection = #Horizontal then

              sp.loc = pStartLoc + point(deltaMouse[1], 0)

            else

              sp.loc = pStartLoc + point(0, deltaMouse[2])

            end if

          end enterFrame

          • 2. Re: Drag horizontally
            anjemalo Level 1

            You are the best.

            I want to lock my big sprite to the right and to the left I'm writing this code but this not work, It locks the sprite but cannot move it anymore.

            Can you help me please?

            Thank you very much.

             

            on mouseDown me

              pStartLoc = sp.loc

              pMouseStart = _mouse.mouseLoc

              if sp.left<=0 then

                sp.locH=0

                pMoving = false

              else

                pMoving = true

              end if

            end mouseDown