-1

我面临一个问题,也就是说,我有几个物理体,它们的形状在物理编辑器中定义,我正在使用那个 .lua 文件作为形状。但是我找不到如何分别在 X 轴和 Y 轴上应用缩放?有什么帮助吗?

4

1 回答 1

1

如果您使用Andreas Loew / code-and-web.de的物理编辑器

你可以试试这段代码

这是实现

local scaleX = 0.5
local scaleY = 0.2
local physicsData = (require ("your.physics.object")).physicsData(scaleX,scaleY) --This is the scaling of the physics body
object = display.newImage("youimage.png")
object.xScale = scaleX
object.yScale = scaleY
physics.addBody( object, "static", physicsData:get("physics_dody") )

在物理编辑器 Lua(您的 .lua 形状)上,您必须更改以下代码

function M.physicsData(scale)

function M.physicsData(scaleX,scaleY)

local s = scale or 1.0
for bi,body in pairs(physics.data) do
    for fi,fixture in ipairs(body) do
        if(fixture.shape) then
            for ci,coordinate in ipairs(fixture.shape) do
                fixture.shape[ci] = s * coordinate
            end
        else
            fixture.radius = s * fixture.radius
        end
    end
end

local sX = scaleX or 1.0
local sY = scaleY or 1.0
for bi,body in pairs(physics.data) do
    for fi,fixture in ipairs(body) do
        if(fixture.shape) then
            for ci,coordinate in ipairs(fixture.shape) do
                if (ci%2) == 0 then
                    fixture.shape[ci] = sX * coordinate
                else
                    fixture.shape[ci] = sY * coordinate
                end
            end
        else
            fixture.radius = sX * fixture.radius
        end
    end
end
于 2013-06-26T00:50:48.690 回答