Maybe not possible? Groups/Physics & Text Disappearing on Contact....

So I think I remember reading that when you're applying physcis to objects, they all need to reside in the same display group, so that could very well be my problem--since I am inserting objects into a display group, and then inserting those groups into my main display group, and then applying the phyics paramters to each group. BUT, that does seem to work. The only odd thing I'm seeing is that when two objects collides (two of the circles in the below code), the text disappears, as if it's been knocked away somewhere. Anyone have any idea what's wrong, or if I'm just doing this all wrong to begin with?

Thanks,
Scott.

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
    local localGroup = display.newGroup()
    local popCircles = {};
 
    local background = display.newImageRect("bg-lateevening.png",768,1024)
          background:setReferencePoint(display.TopLeftReferencePoint)
          background.x = 0
          background.y = 0
          localGroup:insert(background)
 
    local borderBottom = display.newRect(localGroup, 0, 900, 768, 4 )
          borderBottom:setFillColor( 255,255,255)       -- make invisible
          borderBodyElement = { friction=0.4, bounce=0.8 }
          
          physics.addBody( borderBottom, "static", borderBodyElement )
 
 
    --loop over circles.
    for i=1,2 do
        local group = display.newGroup()
        local redBody = { density=0.2, friction=0, bounce=0.95, radius=50.0}
 
        popCircles[i] = display.newCircle( 0, 0, 50 )
        popCircles[i]:setFillColor(255,255,255)
        popCircles[i].id = i
        popCircles[i]:setReferencePoint(display.CenterReferencePoint)
 
        group:insert(popCircles[i])
    
    
        local label = display.newText(group,i,0,0,native.systemFontBold,24)
        label:setTextColor(0,0,0)
        label.x = popCircles[i].x
        label.y = popCircles[i].y
        label:toFront();
        --group:addEventListener("touch",rectTouchListener)
    
        group:setReferencePoint(display.CenterReferencePoint)
        group.x = math.random(0,300) ;
        group.y = math.random(0,1024) ;
 
        physics.addBody( group, redBody )
    
        localGroup:insert(group)
 
    end

local physics = require( "physics" )
physics.start()

Try adding this before you begin adding bodies.

views:1510 update:2011/11/27 10:14:33
corona forums © 2003-2011