1 Reply Latest reply on Apr 22, 2013 8:25 AM by Minds Eye

    Restrict horizontally

    anjemalo Level 1

      Hello:

      I need to restrict to horizontally my sprite.

      I don't know where to put the code for restriction.

      Can you guide me, please?

      thank you

       

      Here is the code:

       

      property pThrowSpan, pMode, pCurrentLoc, pLocList, pMoveAmount

      property pClickDiff

      property sp

       

      on getPropertyDescriptionList me

        list = [:]

        addProp list, #pThrowSpan, [#comment: "Frame Span of Throw",\

          #format: #integer, #range: [#min: 1, #max: 20],\

          #default: 5]

        return list

      end

       

      on beginSprite me

        sp = sprite(me.spriteNum)

        pMode = #normal

      end

       

      on mouseDown me

        pMode = #pressed

        pLocList = []

        pClickDiff = sp.loc - the clickLoc

      end

       

      on mouseUp me

        throw(me)

      end

       

      on mouseUpOutside me

        throw(me)

      end

       

      on throw me

        if pLocList.count > 0 then

          pMoveAmount = (the mouseLoc - pLocList[1])/pThrowSpan

          pMode = #throw

        end if

      end

       

      on exitFrame me

        if pMode = #pressed then

          pCurrentLoc = the mouseLoc

          sp.loc = pCurrentLoc+ pClickDiff

          pLocList.add(pCurrentLoc)

          if pLocList.count > pThrowSpan then pLocList.deleteAt(1)

         

        else if pMode = #throw then

          pCurrentLoc = pCurrentLoc + pMoveAmount

          sp.loc = pCurrentLoc+ pClickDiff

          pMoveAmount = pMoveAmount * .9

        end if

      end

        • 1. Re: Restrict horizontally
          Minds Eye Level 1

          Depends on when you want the sprite to be restricted to the the horizontal axis. While dragging?  when throwing? Or both?

          If it's while dragging and throwing, you might want to change your code so that it's only using the loch part of the point locations. (e.g. the mouseH, point.locH etc.)