为什么这个碰撞代码不起作用? (love2d)
Why does this collision code not work? (love2d)
function love.collide ()
if x < 0 then
x = 0
end
if x < love.graphics.getWidth () - Dolphin:getWidth () then
x = love.graphics.getWidth () - Dolphin:getWidth ()
end
end
我正在尝试进行 x 坐标碰撞,并且我之前已经定义了 x。没有错误,但碰撞失败。
我想你的意思是 x > love.graphic.getWidth() - Dolphin:getWidth()
。因为否则你的 Dolphin
应该总是卡在右手边界。
我假设你想检测你的物体(Dolphin
)和屏幕边界之间的碰撞,但你不是在比较物体的位置(变化);相反,你比较对象的宽度,它可能不会改变。
function love.collide ()
if x < 0 then
x = 0
end
if x < love.graphics.getWidth () - Dolphin:getWidth () then
x = love.graphics.getWidth () - Dolphin:getWidth ()
end
end
我正在尝试进行 x 坐标碰撞,并且我之前已经定义了 x。没有错误,但碰撞失败。
我想你的意思是 x > love.graphic.getWidth() - Dolphin:getWidth()
。因为否则你的 Dolphin
应该总是卡在右手边界。
我假设你想检测你的物体(Dolphin
)和屏幕边界之间的碰撞,但你不是在比较物体的位置(变化);相反,你比较对象的宽度,它可能不会改变。