在碰撞檢測回調中檢查以下內容。
if(y-origin of the first animal + its height < the y-origin of the second animal){
//then do the logic for walking on top of another animal (probably nothing would happen here depending on what you are trying to build)
}
else {
//forward to collision logic (e.g life loss, lose points, restart level ,etc..)
}
,如果有可能的第一個動物進入第二隻動物的下方,那麼你需要更新你的病情以下
if(firstAnimal.origin.y + firstAnimal.frame.size.height < secondAnimal.frame.origin.y
|| firstAnimal.origin.y > secondAnimal.frame.origin.y + secondAnimal.frame.size.height)
警惕的不同座標可能有時混淆系統。希望這可以幫助,隨時詢問是否有什麼不清楚的地方。
感謝您的回答!我已經多次嘗試過,但還沒有奏效。我已經在 –
之上發佈了我的代碼,嘗試記錄獅子的原始值和高度,以瞭解發生了什麼。如果沒有任何意義嘗試使用的位置,而不是如下代碼 – rockstarr
我認爲我在代碼中發現問題,在skscene中原點位於左下角,因此條件應該更改爲 大於 if(lionNode.frame.origin。 y + lionNode.frame.size.height> animalNode.frame.origin.y) – rockstarr