更改对象大小后自动更改对象的物理特性

时间:2013-06-05 07:46:00

标签: lua corona

我是Corona和Lua的新手。我有以下问题:

我有一个带有这些物理参数的对象cake(并不重要):

["cake1"] = {




                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   -21, 62.5  ,  -36, 62.5  ,  -50, 55.5  ,  -58.5, 46  ,  -36, -38.5  ,  57, -40.5  ,  57.5, 34  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   -7.5, -63  ,  -13, -61.5  ,  -12, -64.5  ,  -8, -64.5  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   -12, -64.5  ,  -13, -61.5  ,  -17.5, -56  ,  -21, -52.5  ,  -18.5, -60  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   -47, -37.5  ,  -58.5, 46  ,  -58.5, -33  ,  -53, -37.5  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   -26, -52.5  ,  -21, -52.5  ,  -18.5, -52  ,  -9, -47.5  ,  -6.5, -41  ,  -36, -38.5  ,  -34.5, -46  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   -36, -38.5  ,  -58.5, 46  ,  -47, -37.5  ,  -42, -39.5  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   -6.5, -41  ,  -9, -47.5  ,  -6.5, -44  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   25, -40.5  ,  7, -40.5  ,  17, -42.5  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   48, -42.5  ,  57, -40.5  ,  25, -40.5  ,  32, -42.5  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   -18.5, -52  ,  -21, -52.5  ,  -17.5, -56  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   7, -40.5  ,  -36, -38.5  ,  -6.5, -41  }
                    }
                     ,
                    {
                    pe_fixture_id = "", density = 2, friction = 0, bounce = 0, 
                    filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },
                    shape = {   25, -40.5  ,  -36, -38.5  ,  7, -40.5  }
                    }



        }

当我将它插入场景时,我得到以下结果:

enter image description here

cake太大,所以我用cake1:scale(0.5,0.5)来改变他的大小。问题是物理没有自动改变以适用于它的新大小,结果是:

enter image description here

有没有简单的方法来改变对象的大小,物理自动适应新的大小,或者我必须重写它们?

2 个答案:

答案 0 :(得分:11)

您是否正在使用物理编辑器??

然后提供scaleFactor。您可以使用此比例因子为物体指定物理,如下所示:

local scaleFactor = 1.0
local physicsData = (require "shapedefs").physicsData(scaleFactor)
local shape = display.newImage("objectname.png")
physics.addBody( shape, physicsData:get("objectname") )

当您更改scaleFactor时,物理区域的大小将自动更改。

有关详细信息,请访问:http://velluminteractive.com/advanced-physics-bodies-with-physics-editor-and-corona-sdk/

答案 1 :(得分:0)

你已经将比例尺改为0.5更小,意味着你必须将所有物理对象变小0.5,使用计算器来制作你的正常数字/ 2和数字小于0/2的数字,并用结果数加上你的数字,这里是一个例子:

24 = 12

-24 = -36