【问题标题】:Why does this collision code not work? (love2d)为什么这个碰撞代码不起作用? (爱2d)
【发布时间】:2016-06-17 13:05:03
【问题描述】:
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。没有错误,但碰撞无法正常工作。

【问题讨论】:

    标签: lua collision love2d


    【解决方案1】:

    我想你的意思是x &gt; love.graphic.getWidth() - Dolphin:getWidth()。因为否则您的Dolphin 应该始终停留在右侧边界。

    【讨论】:

      【解决方案2】:

      我假设你想检测你的对象(Dolphin)和屏幕边界之间的碰撞,但你没有比较对象的位置(变化);相反,您比较对象的宽度,这可能不会改变。

      【讨论】:

      • 当我使用 getWidth 时,我得到的是窗口大小的宽度,而不是对象的宽度。但是,我确实通过将其更改为函数 love.update 来使其工作
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多