如何在LOVE2D的重复循环中使用hump.timer?
如何在LOVE2D中进行重复外观,以便使角色移动 我试过了如何在LOVE2D的重复循环中使用hump.timer?,timer,lua,wait,repeat,love2d,Timer,Lua,Wait,Repeat,Love2d,如何在LOVE2D中进行重复外观,以便使角色移动 我试过了 function love.keypressed(key) if key=='left' then repeat imgx=imgx+1 timer.after(1,function() end) until not love.keyboard.isDown('left') end end 但是没用,请帮帮我 当按下一个键时,听起来像是在试图移动图像。为此,使用第三方库计时器过于复杂 您希望将一些X和Y变量与图像关联,并使用这些变量绘
function love.keypressed(key)
if key=='left' then
repeat
imgx=imgx+1
timer.after(1,function() end)
until not love.keyboard.isDown('left')
end
end
但是没用,请帮帮我 当按下一个键时,听起来像是在试图移动图像。为此,使用第三方库计时器过于复杂 您希望将一些X和Y变量与图像关联,并使用这些变量绘制图像。如果需要连续移动,可以使用回调或通过检查按键来更改它们 例如:
function love.load()
sprite = {x=0, y=0, image=love.graphics.newImage("test.jpg")}
speed = 3
end
function love.update(dt)
if love.keyboard.isDown("left") then sprite.x = sprite.x - speed end
if love.keyboard.isDown("right") then sprite.x = sprite.x + speed end
if love.keyboard.isDown("up") then sprite.y = sprite.y - speed end
if love.keyboard.isDown("down") then sprite.y = sprite.y + speed end
end
function love.draw()
love.graphics.draw(sprite.image, sprite.x, sprite.y)
end
当按下一个键时,听起来像是在试图移动图像。为此,使用第三方库计时器过于复杂 您希望将一些X和Y变量与图像关联,并使用这些变量绘制图像。如果需要连续移动,可以使用回调或通过检查按键来更改它们 例如:
function love.load()
sprite = {x=0, y=0, image=love.graphics.newImage("test.jpg")}
speed = 3
end
function love.update(dt)
if love.keyboard.isDown("left") then sprite.x = sprite.x - speed end
if love.keyboard.isDown("right") then sprite.x = sprite.x + speed end
if love.keyboard.isDown("up") then sprite.y = sprite.y - speed end
if love.keyboard.isDown("down") then sprite.y = sprite.y + speed end
end
function love.draw()
love.graphics.draw(sprite.image, sprite.x, sprite.y)
end
是否要移动角色或更改其精灵图像(由于
imgx
,因此不确定)?基本移动不需要驼峰
模块。我想用它来移动角色。arthurgps2:你想要连续移动(必须按住按钮才能使角色移动很远)还是离散移动(点击按钮一次,角色移动整个方块或瓷砖)?是否要移动角色或更改其精灵图像(由于imgx
,因此不确定)?基本移动不需要驼峰
模块。我想用它来移动角色。arthurgps2:你想要连续移动(你必须按住按钮才能使角色移动很远)还是离散移动(点击按钮一次,角色移动整个方块或平铺)?