Can physic objects scale?

i have an image, it’s easy to turn them into physic object by just calling addBody method.

But i am concern when the level is scaled, let say 2X larger, then the image can scale easily, but it seems like the physic body will remain unchanged.

In such a case, how can achieve the physic object scaling? and even challenging if i have > 20 objects on screen.

Can someone show some light?

Thanks [import]uid: 10373 topic_id: 19666 reply_id: 319666[/import]

you might want to use custom physics shapes in that case
pity, but corona still doesnt support scaling of physics bodies well [import]uid: 16142 topic_id: 19666 reply_id: 75991[/import]

interesting problem. with custom physics shape, is it possible to have several shapes assigned to 1 object and use those dependent on scaling? [import]uid: 109677 topic_id: 19666 reply_id: 76090[/import]

if you refer to scaling iPhone/iPad portrait screens, then it should not be a problem: just be sure your config.lua is as follows:
[lua]application = {
content = {
width = 320,
height = 480,
scale = “letterBox”, – letterBox scales all for you
fps = 30,
}
} [/lua]

letterBox scales all for you and worked well for my iPhone/iPad (that is universal app) game [import]uid: 67641 topic_id: 19666 reply_id: 76102[/import]

physics bodies do not scale by changing .xScale/.yScale or :scale()

The display object will scale properly, but the physics body associate with it stays the same size.

[import]uid: 19626 topic_id: 19666 reply_id: 76105[/import]

Thanks for all the reply but it’s really SAD to hear that!
Don’t see this under the Corona roadmap too.

My game idea is expand based this feature [import]uid: 10373 topic_id: 19666 reply_id: 76118[/import]

@weilies: As with many other things, there are workarounds for features that are not built-in. In your case, what I’d recommend is create a method that handles changing the xScale and yScale of an object, and also removes the physics body and recreates it.

Using this method, you’d have to store a reference to your shape table to the object. The example below assumes you have a reference to the object’s shape table within a ‘bodyShape’ property (which you would have to set manually when you create the object).

Here’s an example:

-- method to change xScale and also modify bodylocal function changeScale( self, xScale, yScale ) -- modify object's xScale & yScale property (easy part) self.xScale = xScale self.yScale = yScale -- multiply the shape by the object's new scale local shape = self.bodyShape for i=1,#shape,2 do shape[i] = shape[i] * xScale shape[i+1] = shape[i+1] * yScale end -- remove and re-add physics body physics.removeBody( self ) physics.addBody( self, { shape=shape } )end-- now, be sure to add the method to your objects:obj1.changeScale = changeScaleobj2.changeScale = changeScale-- and when you need to scale an object:obj1:changeScale( 2.0, 2.5 )[/code]Some notes on the above:The changeScale() method as it is written above does not scale relative to object's current scale (as the scale() method does), it just changes the xScale and yScale to exactly what you set it to in the function arguments.Also, if you assign the method to objects as in the example above, when you call the method, don't forget to call it using a ':' instead of a '.'.Hope that helps!NOTE: I haven't tested the above code, so it's not guaranteed to be error-free, but the logic behind it should still apply just fine. [import]uid: 52430 topic_id: 19666 reply_id: 85673[/import]