2016-03-03 25 views
1
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以前。沒有錯誤,但碰撞失敗。爲什麼這個碰撞代碼不起作用? (love2d)

回答

1

我想你的意思是x > love.graphic.getWidth() - Dolphin:getWidth()。因爲否則你的Dolphin應該總是卡在右邊界。

0

我假設你想檢測你的對象(Dolphin)和屏幕邊界之間的碰撞,但是你沒有比較對象的位置(哪一個會改變)。而是比較對象的寬度,該寬度可能不會更改。

+0

當我使用getWidth,我得到我的窗口大小的寬度不是對象的寬度。但是,我確實通過將其更改爲函數love.update來獲得此功能 –