Search code examples
livecodegraphic

Is it possible to have a user draw a graphic in livecode?


For a game I am working on the user must draw a line and an object will follow the line. To me it would be logical for the user's line to be a graphic and then do something like this (the user's line is called "userLine")

move the image "xyz" to the points of graphic "userLine"

is it possible to have the user draw a graphic?


Solution

  • Check out the choose command. This should get you started.

    To start out drawing your line: (This could be in a a button script, for example. However you want to trigger the user drawing.)

    if there is a graphic "userLine" then
        delete graphic "userLine"
    end if
    set the style of the templateGraphic to "line"
    set the selectionHandleColor to the effective backgroundcolor of this card
    choose graphic tool
    

    Then in the card script add the following handler:

    on newGraphic
       choose browse tool
       set the selectionHandleColor to black
       set the name of graphic (the number of graphics) to "userLine"
       move btn "radio" to the points of grc "userLine" in 2 seconds
    end newGraphic
    

    Some variation of this should work.