【问题标题】:How to get the Fixture of an "Object Layer"? LOVE 2d, Lua, Tiled如何获得一个“对象层”的Fixture? LOVE2d,Lua,瓷砖
【发布时间】:2022-12-18 21:38:03
【问题描述】:

我正在尝试制作 PacMan 的怪异版本,我需要一种快速的方法来绘制整个地图上的所有点(菱形)。 我的想法是用一个循环在每个 x,y 上绘制一个点,然后检查哪些点与墙碰撞并删除它们。 唯一的问题是我不知道如何获得墙壁的固定装置。 我将 Tiled 与 STI 库一起使用,并制作了一个可碰撞的对象层。 我是菜鸟,我不知道您需要哪些信息来帮助我,请告诉我您需要知道的信息。 太感谢了

function Coin.beginContact(a, b, collision)
    for i,instance in ipairs(ActiveCoins) do
        if a == instance.physics.fixture or b == instance.physics.fixture then
            if a == Player.physics.fixture or b == Player.physics.fixture then
                instance.toBeRemoved = true
                return true
            elseif a == map.layers.Solid or b == map.layers.Solid then
                instance.toBeRemoved = true
                return true
            end
        end
    end
end

这就是我检查 Player 和 Coins 之间碰撞的方式,在 elseif 中我试图进行实验以获得墙壁的固定装置,但是 nada。

【问题讨论】:

    标签: lua love2d tiled


    【解决方案1】:

    要获取地图中墙壁的固定装置,可以使用 Map 对象的 getFixtures 方法。此方法返回地图中所有固定装置的列表,您可以使用此列表检查与墙壁的碰撞。

    下面是一个示例,说明如何使用 getFixtures 方法获取地图中墙壁的固定装置:

    function Coin.beginContact(a, b, collision)
        for i,instance in ipairs(ActiveCoins) do
            if a == instance.physics.fixture or b == instance.physics.fixture then
                if a == Player.physics.fixture or b == Player.physics.fixture then
                    instance.toBeRemoved = true
                    return true
                else
                    local fixtures = map.layers.Solid:getFixtures()
                    for j,fixture in ipairs(fixtures) do
                        if a == fixture or b == fixture then
                            instance.toBeRemoved = true
                            return true
                        end
                    end
                end
            end
        end
    end
    

    在此示例中,在 map.layers.Solid 对象上调用 getFixtures 方法以获取地图实体层中所有固定装置的列表。然后使用 for 循环迭代此列表,并且代码检查当前夹具是否涉及碰撞。如果是,代码设置 toBeRemoved

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多