Line follow cursor

  • #1, z nikos papaFriday, 05. May 2017, 12:31 hodinky 8 years ago
    Is it possible to create in lua a line that follows cursor. Or how can we follow cursor.

    Bažant

    25 Posts


  • #2, z ke4Friday, 05. May 2017, 13:22 hodinky 8 years ago
    Yes, there's the new draw function that allows that.

    drawLine(x, y, x2, y2, color, alpha) 

    You can get the current cursor position by getCursorPos() function.
    So you could do something like this:
    graphics.addDrawFunc("draw()", 0) 
    
    function draw() 
    
    graphics.drawLine(0, 0, getCursorPos().x, getCursorPos().y, 000, 1.0) 
    
    end 

    Zabiják klíčů

    810 Posts

  • #3, z stroncisFriday, 05. May 2017, 14:25 hodinky 8 years ago
    And if you want that not just end of the line, but whole line to follow, simple line dragging:
    graphics.drawLine(getCursorPos().x-50, getCursorPos().y, getCursorPos().x+50, getCursorPos().y, 000, 1.0)  
    

    This makes horizontal line to follow cursor. By modifying x and y coordinates, you can rotate it or make at some distance from cursor.

    Bažant

    42 Posts

  • #4, z sebastianFriday, 05. May 2017, 15:01 hodinky 8 years ago
    quick questions i have for this :
    - do i have to do this in a loop so the line keeps updated? 

    - how do i delete this line? 

    Kapitán

    2346 Posts

  • #5, z ke4Friday, 05. May 2017, 15:19 hodinky 8 years ago
    It's looping automatically. You can delete the function with removeDrawFunc(name).

    graphics.removeDrawFunc("draw()")

    Zabiják klíčů

    810 Posts