我一直在尝试通过 IUP 获得输入来制作一个小型乒乓球游戏。我想尝试一些输入,并尝试了 IUPGL 示例附带的一些代码,但输入似乎根本不起作用。这是到目前为止的代码:
require "iuplua"
require "iupluagl"
require "luagl"
paddle = {x = -0.9, y = 0.2}
function drawPaddle(x, y)
gl.Begin(gl.QUADS)
gl.Color(0.0, 0.5, 0.0)
gl.Vertex(x, y)
gl.Vertex(x + 0.1, y)
gl.Vertex(x + 0.1, y - 0.4)
gl.Vertex(x, y - 0.4)
end
canvas = iup.glcanvas{buffer = "DOUBLE", rastersize = "300x300"}
function canvas:action(x, y)
iup.GLMakeCurrent(self)
gl.ClearColor(0.0, 0.0, 0.0, 0.0)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Clear(gl.DEPTH_BUFFER_BIT)
gl.MatrixMode(gl.PROJECTION)
gl.Viewport(0, 0, 300, 300)
gl.LoadIdentity()
drawPaddle(paddle.x, paddle.y)
gl.End()
iup.GLSwapBuffers(self)
end
window = iup.dialog{canvas, title = "Soon to be Pong"}
function canvas:k_any(c)
if c == iup.K_q then
return iup.CLOSE
elseif c == iup.K_w then
paddle.y = paddle.y + 0.02
return iup.CONTINUE
else
return iup.DEFAULT
end
end
window:show()
iup.MainLoop()
我的理解是canvas:k_any()
当一个键被按下时会被调用,但它没有响应,即使是退出命令。有任何想法吗?