矩形与矩形碰撞2

来源:互联网 发布:动漫九宫格锁屏软件 编辑:程序博客网 时间:2024/04/28 01:21
 -- local function isCollision(  )
--         -- body
--         local x1 = rect1:getPositionX() - rect1:getAnchorPoint().x * rect1:getBoundingBox().width
--         local x2 = rect2:getPositionX() - rect2:getAnchorPoint().x * rect2:getBoundingBox().width
--         local y1 = rect1:getPositionY() - rect1:getAnchorPoint().y * rect1:getBoundingBox().height
--         local y2 = rect2:getPositionY() - rect2:getAnchorPoint().y * rect2:getBoundingBox().height
--         local distance = math.abs(x2 - x1)
--         print("y1 <= y2 + rect2:getBoundingBox().height",y1 <= y2 + rect2:getBoundingBox().height)
--         if distance <= rect1:getBoundingBox().width and y1 <= y2 + rect2:getBoundingBox().height  then
--             -- print("碰撞了。")
--         end
0 0