[Resolved] Help - is there a way to add multiple circle physics bodies to a display object?

I need four circular physics bodies that are symmetrically placed in four corners of, say invisible square space, and they rotate together around a center of the square. Imagine a invisible square box with four corners, and on each corner, I need to place a circular physics body. And I need to rotate these four circular physics bodies around a center of the invisible square.

I initially made this work by doing the following (not so elegant, but still kind of worked):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        local function newBumper()
                -- circle bumpers
                local bumperGroup = display.newGroup()
 
                bumperBody = {friction=0.5, bounce=0.7, radius=6}
                local circleBumper1 = spriteFactory:newSpriteGroup("circleSpin") -- spriteGroup instance
                local circleBumper2 = spriteFactory:newSpriteGroup("circleSpin")
                local circleBumper3 = spriteFactory:newSpriteGroup("circleSpin")
                local circleBumper4 = spriteFactory:newSpriteGroup("circleSpin")
 
                physics.addBody(circleBumper1, "static", bumperBody);
                physics.addBody(circleBumper2, "static", bumperBody);
                physics.addBody(circleBumper3, "static", bumperBody);
                physics.addBody(circleBumper4, "static", bumperBody);
 
                -- added this to make sure the bumper behaves like a bumper
                circleBumper1.isBullet = true;
                circleBumper2.isBullet = true;
                circleBumper3.isBullet = true;
                circleBumper4.isBullet = true;
 
                --insert display objects to bumperGroup
                bumperGroup:insert(circleBumper1);
                bumperGroup:insert(circleBumper2);
                bumperGroup:insert(circleBumper3);
                bumperGroup:insert(circleBumper4);
                
                circleBumper1:play();  -- animating the spriteGroup
                circleBumper2:play();
                circleBumper3:play();
                circleBumper4:play();
 
                return bumperGroup;
        end     
 
        -- spawn a bumper
        local rotatingBumper = newBumper();
        
        -- position the bumpers
        rotatingBumper[1].x = 0.5 * screenW;
        rotatingBumper[1].y = 0.5 * screenH - 38;
        rotatingBumper[2].x = 0.5 * screenW + 38;
        rotatingBumper[2].y = 0.5 * screenH; 
        rotatingBumper[3].x = 0.5 * screenW;
        rotatingBumper[3].y = 0.5 * screenH + 38;
        rotatingBumper[4].x = 0.5 * screenW - 38;
        rotatingBumper[4].y = 0.5 * screenH;
        
        rotatingBumper.xReference = 0.5 * screenW;
        rotatingBumper.yReference = 0.5 * screenH;
        rotatingBumper.x = 0.5 * screenW;
        rotatingBumper.y = 0.5 * screenH;
        rotatingBumper.rotation = 0;
 
        -- rotate bumper
        local function rotateBumper()
                rotatingBumper.rotation = rotatingBumper.rotation + 2;
        end
        Runtime:addEventListener( "enterFrame", rotateBumper );
 
        local function stopBumper()
                Runtime:removeEventListener( "enterFrame", rotateBumper );
        end

On my ever growing todo list, is to look into what this physicseditor tool does.

http://www.physicseditor.de/features/

It looks like it makes the job of collision detection for odd shaped objects much easier. Maybe it can help with what you're trying to do.

Hi elbowroomapps, thank you so much for the pointer. Among other possible options, I'll take a look at this editor tool too. Thanks again!

Actually, I just looked at how Spriteloq generates odd shaped (or complex) physics body here:

http://www.youtube.com/watch?v=bEyNprBtLY8

I use Spriteloq, and this makes it incredibly easy to work out complex physics body. So I probably don't need another physics editor tool.

That said, I still need to sort out how I might plot out complex physics bodies that must be added to a single display object (that is, multiple of physics bodies that are not touching each other...)

So... I could use physics joints for multiple of physics bodies -- this will pretty much cover everything I would ever need for creating and adding physics body shapes, it seems:

http://developer.anscamobile.com/content/game-edition-physics-joints

P.S. I was also able to do the exact same thing using Spriteloq's Shape Control and a bit of hack (i.e., adding multiple of {} from polys in lua file that Spriteloq spits out). It's pretty awesome. I can add any shape to any instance of SpriteGroup using this tool!

views:1545 update:2011/10/4 8:06:35
corona forums © 2003-2011