【问题标题】:love2d - update the text of printed textlove2d - 更新打印文本的文本
【发布时间】:2014-03-31 09:08:09
【问题描述】:

我打印了“是”的文字。我必须按箭头形状的按钮。我试图得到它,这样如果我点击左箭头,它会说“否”,如果我点击右箭头,就会说“是”。

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 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
end

【问题讨论】:

  • x &gt; 424 and x &lt; 335。选择x。它会同时满足这两个条件吗?
  • 对不起。本来应该是 435。原始帖子已被编辑

标签: text lua updates love2d


【解决方案1】:

怎么样:

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 中声明函数。这段代码 sn-p 会让爱重新定义 love.mousepressed 游戏的每一帧!

【讨论】:

    猜你喜欢
    • 2019-02-08
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    相关资源
    最近更新 更多