# How does one update the physical state of an object after scaling it in Corona?

I am new to Corona and Lua. I have the following question:

I have an object cake with these physics parameters (doesn't really matters):

["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  }
}

}


and when I insert it to the scene I have the following result:

The cake is too large so I use cake1:scale(0.5,0.5) to change his size.The problem is that the physics didn't change automatically to apply to its new size and the result is:

Are there any easy way to change the size of an object and the physics automatically fit to the new size or I have to rewrite them?

Make the values that define your physics body variables, not hard coded values. Then you can scale them at the same time you scale the sprite for your cake.

The easiest way is to move your hard coded values into an array, then loop through the array and scale the values the same as the sprite before creating the physics object.

An alternative, likely easier to implement, but very ugly way, scale all your hard coded values like so:

xScale = .5
yScale = .5

shape = {
-21*xScale,   62.5*yScale ,
-36*xScale,   62.5*yScale ,
-50*xScale,   55.5*yScale ,
-58.5*xScale, 46*yScale ,
-36*xScale,  -38.5*yScale ,
57*xScale,  -40.5*yScale ,
57.5*xScale, 34*yScale }
}