저는 Love2d 프레임 워크에서 간단한 게임에서 오브젝트와 충돌을 관리하기위한 기본 아키텍처를 만들려고합니다. 모든 개체는 테이블 (objects:activeObjects
)에 저장되고 objects:calculateCollisions()
함수의 루프는 모든 개체를 반복합니다. 각 반복마다 다른 중첩 루프가 해당 객체가 동일한 테이블의 다른 객체와 겹치는 지 확인합니다. objects:calculateCollisions()
의 끝에는 각 오브젝트가 이상적으로 현재 시점에서 오버랩하는 모든 오브젝트에 대한 참조를 포함하는 테이블을 가지게됩니다. 그러나 개체에는 항상 빈 충돌 테이블이 있습니다.
지금은 두 가지 테스트 개체가 있습니다. 하나는 마우스로 움직이고 다른 하나는 항상 오른쪽 상단 구석에 머물러 있습니다. 두 객체는 겹칠 때 동시에 사라져야하지만, 앞서 언급했듯이 collidingObjects
테이블은 항상 비어 있습니다.
main.lua
:
나는 세 개의 소스 파일이
(중요한 물건의 대부분을 기록, 아마 어디에 문제가) http://pastebin.com/xuGBSv2j
objects.lua
:
http://pastebin.com/sahB6GF6
customObjects.lua
(여기서 두 테스트 객체의 생성자) 정의 :
사각 충돌 시스템이 love2d에서 작동하지 않습니다.
function objects:newCollidingObject(x, y)
local result = self:newActiveObject(x, y, 50, 50)
result.id = "collidingObject"
function result:collide(other)
if other.id == "collidingObject" then self.remove = true end
end
return result
end
function objects:newMovingObject(x, y)
local result = self:newCollidingObject(x, y)
function result:act()
self.x = love.mouse.getX()
self.y = love.mouse.getY()
end
return result
end
미안 해요, 두 개 이상의 하이퍼 링크를 게시 할 수 없습니다.
편집 : 좀 더 디버깅을 한 후에는 collidesWith(obj)
기능으로 문제를 좁혔습니다. 항상 거짓을 반환하는 것 같습니다.
function result:collidesWith(obj)
if self.bottom < obj.top then return false end
if self.top > obj.bottom then return false end
if self.right < obj.left then return false end
if self.left > obj.right then return false end
return true
end
해당 속성이 유효합니까? (두 개체의 맨 아래, 맨 위, 오른쪽 및 왼쪽) – Darkwater