love2d - 更新已打印文本的文本内容。

我已经打印了一个写着“Yes”的文本。并且有两个箭头形状的按钮。我想让左箭头被点击时它会说"No",而右箭头被点击时会说"Yes"。

fsdefault = "Yes"
fs = love.graphics.print(fsdefault, 440, 160)
love.graphics.draw(larrow, 425, 163)
love.graphics.draw(rarrow, 470, 163)

function love.update(dt)
function爱.mousepressed(x, y)
    if x > 424 and x < 435 and y > 161 and y < 172 then
        fsdefault = "No"
    end

    如果 x > 275 and x < 320 and y > 305 and y < 325 then
        fsdefault = "Yes"
    end
end
end
点赞
用户3080396
用户3080396

如何使用类似于以下内容的语句:

local fsdefault = ""
function love.mousepressed( x, y)
    if x > 424 and x < 435 and y > 161 and y < 172 then
        fsdefault = "No"
    end

    if x > 275 and x < 320 and y > 305 and y < 325 then
        fsdefault = "Yes"
    end
end

function love.draw()
    love.graphics.print(fsdefault, 440, 160)
    love.graphics.draw(larrow, 425, 163)
    love.graphics.draw(rarrow, 470, 163)
end

请注意,为了清晰起见,应仅在 love.draw 内部执行屏幕绘制操作。

另外,尽量避免在 love.update 内声明函数。该代码片段将使 love 重新定义 love.mousepressed 游戏的每一帧!

2014-02-28 12:50:43