How to scale a group and objects within as one? effect physics?

Hello everyone,
How do you scale a group and objects in that group as one? Can i do that with group.xScale and group.yScale? And if that is possible, does it effect the the physics ( objects moving , rotating, ...). And if it is not possible, do you have any suggest to scale down all the objects in a group without having effect the physics? Thanks.

I would suggest you read up a little more on scaling before using it as it will cause you some headaches where physics is involved, yes.

Peach

I know that the objects' physic bodies will not be scaled down along when i scale the group which contains the objects, and second thing is involving in objects position in the scene when objects are scaled down. This sounds complicated, scaling the whole scene with many of objects in a group (with physics involved) with fingers (multitouch), is what is needed for my game. The PinchZoonGesture example in the Interface folder is good, but it doesn't help me because it does not deal with physics. Look at the game Angry bird, scaling in the game with fingers (multiple touches) was done so well. Is there any different approach, or any any way to help me finish this? Thanks. This bugs me so many days.

Any suggestion??

As discussed and as you apparently know, physics bodies will not scale down like images, so, moving on;

If you attempt to resize a group using;
myGroup.xScale =0.5
or whatnot, it will change their positions.

There are various ways to avoid that but here is a quick example I put together for you;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
localGroup = display.newGroup()
 
local circle1 = display.newCircle( 160, 300, 30 )
localGroup:insert( circle1 )
 
local circle2 = display.newCircle( 160, 400, 30 )
localGroup:insert( circle2 )
 
local function shrink ()
        for i = 1, localGroup.numChildren do
        localGroup[i].xScale = 0.5
        localGroup[i].yScale = 0.5
        end
end
circle1:addEventListener("tap", shrink)

peach, your shrink method shrinks object's visual display, not its physical shape, so the collisions between objects will be wrong after scaling. For instance, before scaling two ball objects have physical shape of a circle with 30 pixel-diameter are next to each other. After scaling, their visual displays scale but they will collide to each other even they have a distance (because the physics diameters are the same, the visual diameters are half smaller). I can't figure out how to overcome this.

I guess you should just remove the bodies and recreate them accordingly.
http://developer.anscamobile.com/reference/index/physicsremovebody
Not the best and easier way, but if there's no way to scale them with the display objects, I don't think there are other ways to do this \:

i don't know if after remove all the physics bodies, and recreate them immediately ( just after a move of two fingers on screen), would the events like enterFrame, collision ... crash ? I'm worried because i my objects are animated (moving on a path), and the collisions occur often. Will i have to remove and add events along when i remove physics bodies? The same question with the objects properties (like fixedRotation, isBullet, ...) which may effect how the collisions occur. What exactly happens when you remove a physics body, does it mean, its events (postCollision, enterFrame ,....) will automatically be removed ? How about other properties of the visual display object?. This is a new API, i don't find much information about it.

@dreamer, I've had success doing what you initially guessed might work. Just insert all your physics objects into a single parent group (you could call it zoomGroup for example), then scale the group with zoomGroup.xScale = blah and zoomGroup.yScale = blah.

What IS currently broken is Corona's hybrid and debug physics display. The bounding box physics shapes DON'T scale correctly when you scale the group. So if you have debug or hybrid display on and scale the group it looks like the physics bodies aren't scaling correctly, but you'll see that the objects actually do collide and react as expected. It's just the bounding box display that is incorrect (and very misleading I might add, since these are supposed to be for our benefit when debugging physics!).

Also, remember to insert ALL your physics objects in the same group, otherwise you WILL have problems with physics interactions.

Good luck

views:1688 update:2011/10/18 15:01:22
corona forums © 2003-2011