Search code examples
androidgraphicsluagideros

Lua Gideros: Draw Line with touch


In my game using Lua and Gideros studio, I want someone to be able to draw a straight line with touch by making the beginning of the line where they touched the screen, and the end of the line where they released. When I run my code (below) I always get this message:

main.lua:66: attempt to index global 'event' (a nil value) stack traceback: main.lua:66: in main chunk

Here is my code:

local function onMouseDown(event)
    event.x = startx
    event.y = starty

    event:stopPropagation()
end

local function onMouseUp(event)
    event.x = endx
    event.y = endy
    event:stopPropagation()
    local line = Shape.new()
    line:setLineStyle(5, 0x0000ff, 1)
    line:beginPath()
    line:moveTo(startx,starty)
    line:lineTo(endx,endy)
    line:endPath()

end

This next line is line 66 in my code:

scene:addEventListener(event.MOUSE_DOWN, onMouseDown)
scene:addEventListener(event.MOUSE_UP, onMouseUp)

Anybody know why this is happening? Thanks!


Solution

  • It's because it is Event.MOUSE_DOWN, Lua is case sensitive.