【问题标题】:Lua Gideros: Line with touch 2Lua Gideros: Line with touch 2
【发布时间】:2014-10-14 21:07:04
【问题描述】:

在我使用 Lua 和 Gideros 工作室的游戏中,我希望有人从鼠标向下到鼠标向上画一条直线。这是我的代码不起作用:

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

    event:stopPropagation()
end

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

place:addEventListener(Event.MOUSE_DOWN, onMouseDown)
place:addEventListener(Event.MOUSE_UP, onMouseUp)

有人知道为什么这不起作用吗?谢谢!

这是我的另一个问题的第 2 部分。

【问题讨论】:

    标签: graphics lua gideros


    【解决方案1】:

    如果你说不工作,你的意思是什么都没有发生,屏幕上什么也没有画出来,那是因为你没有将你的形状添加到舞台层次

    应该是这样的:

    local line = Shape.new()
    line:setLineStyle(5, 0x0000ff, 1)
    --can add to stage or maybe place, 
    --if that's what you are using for scene
    stage:addChild(line)
    
    local function onMouseDown(event)
        startx = event.x
        starty = event.y
    
        event:stopPropagation()
    end
    
    local function onMouseUp(event)
        line:beginPath()
        line:moveTo(startx,starty)
        line:lineTo(event.x,event.y)
        line:endPath()
        event:stopPropagation()
    end
    
    place:addEventListener(Event.MOUSE_DOWN, onMouseDown)
    place:addEventListener(Event.MOUSE_UP, onMouseUp)
    

    【讨论】:

    • 非常感谢!它终于奏效了!我真的很高兴,因为这让我无法继续使用我的应用程序!
    猜你喜欢
    • 2014-11-23
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 2014-11-24
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 2022-08-05
    相关资源
    最近更新 更多