Method to rotate combination dial lock face?

  • #1, by jeffWednesday, 22. August 2018, 19:00 6 years ago
    We have a puzzle originally programmed in Director (ages ago) where the user grabs the dial of the combination lock and moves it in a circle to the correct number. The number is registered once a MouseUP is registered. This is done 3x and then I test the 3 numbers against the proper code.

    I can't find is a way to do that within VS currently other than to simply have them click on one side for clockwise and click on the other side for counter-clockwise. But I would like to have the original behavior.

    Newbie

    17 Posts


  • #2, by afrlmeWednesday, 22. August 2018, 21:06 6 years ago
    When you say mouseUP, you are talking about listening out for actual mouse movement on the y-axis & not left mouse button release?

    We don't have an event handler for mouse directions, but you can listen out for mouse movements & check the current position on the y-axis from the position where the user pressed the mouse button down to see if they move the mouse up or down enough to execute the line/function that should update the number.

    Imperator

    7278 Posts

  • #3, by jeffWednesday, 22. August 2018, 22:11 6 years ago
    When you say mouseUP, you are talking about listening out for actual mouse movement on the y-axis & not left mouse button release?

    We don't have an event handler for mouse directions, but you can listen out for mouse movements & check the current position on the y-axis from the position where the user pressed the mouse button down to see if they move the mouse up or down enough to execute the line/function that should update the number.
    Sorry. Let me clarify smile 

    When holding the left mouse button down, and user moves mouse in circle, animation dial animates fwd or reverse UNTIL user releases mouse button ("mouseUP").

    The script I used in another application coverted the mouse coordinates to a 0-360 degree and I used that to determine which animation sprite to display.

    The old code looked like this:
    on mouseDown
    
      repeat while the mouseDown -- LOOP
        a= GetAngle ( (the mouseH, the mouseV) - sprite[Num].loc )
        getDialNum a, sprite[Num]
        updateStage
      end repeat
    
    end
    
    on GetAngle thePoint
    
      set x to the locH of thePoint
      set y to the locV of thePoint
      
      if y = 0 then set angle to 90
      else set angle to atan(float(x) / y) * -180/pi()
      
      if y >= 0 then set angle to 180 + angle
      else if x = 0 and angle = 270 then set angle to 90
      
      return angle
    end  
    
    on getDialNum theAngle, theSpriteNum
    
      put 260 - (theAngle/6) into absDialNum
      set newDialNum = absDialNum + tolerance
      
      if newDialNum 259 then set newDialNum = 199 + (newDialNum - 259)
      
      put absDialNum into prevAbsDialNum
      rotateDial newDialNum, theSpriteNum, startDialNum
    
    end

    Newbie

    17 Posts

  • #4, by sebastianThursday, 23. August 2018, 08:45 6 years ago
    Would be doable with Lua.
    I would suggest you create the turnable dial as an object with the dial as its image. 

    The object rotation can be manipulated via lua script. 

    Regarding to the lua docs i would use the :to tweening function to rotate the dial animation by the angle the mouse cursor stands to the dials center point (caution: use math here wink

    Here is an old topic i found where the needed stuff for a object rotation is described:


    hope that helps smile 

    Thread Captain

    2346 Posts