DE EN FR ES IT CZ
Back Back to top

Line follow cursor

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  • #1, by nikos papa 10 years ago Quote
    Is it possible to create in lua a line that follows cursor. Or how can we follow cursor.
  • New to Visionaire Studio?

    Create point and click adventures without coding. The free version covers up to 25 scenes per project. For more scenes or to earn money with your game, you need a license.

    See the Indie Bundle Try it for free
  • #2, by ke4 10 years ago Quote
    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 

  • #3, by stroncis 10 years ago Quote
    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.
  • #4, by sebastian 10 years ago Quote
    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? 
  • #5, by ke4 10 years ago Quote
    It's looping automatically. You can delete the function with removeDrawFunc(name).

    graphics.removeDrawFunc("draw()")