我正面临一个问题,就是我有几个物理实体,他们的形状是在物理编辑器中定义的,我正在使用那个.lua文件来形状。但我无法找到如何分别在X和Y轴上应用Scaling? 有帮助吗?
答案 0 :(得分: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