Can you change the radius of a circle physics object after its created?

I don’t seem to be able modify it during the draw cycle.

Mark

I hate to bump but would like to know the answer. The docs that I read don’t indicate it is a read only value.

@Marksolberg

Yes. See the example below. Run the program below until the falling circle disappears. Restart the program and after the circle starts falling, double tap the screen to increase it’s size. The collision still works properly. You have to save the original objects values, destroy it, and create the new object with the old values, changing the values you want, in this case, the radius.


function setup() 
    supportedOrientations(PORTRAIT)
    rad=50
    
    c1 = physics.body(CIRCLE,rad)
    c1.x=250
    c1.y=900
    
    c2 = physics.body(CIRCLE,50)
    c2.x=300
    c2.y=300
    c2.type=STATIC
end

function draw()
    background(40,40,50)
    stroke(255)
    strokeWidth(1)
    noFill()   
    ellipse(c1.x,c1.y,rad*2,rad*2) 
    ellipse(c2.x,c2.y,100,100)
end

function touched(t)
    if t.state==BEGAN then
        if t.tapCount==2 then
            rad=75    -- increase the radius
            c1x=c1.x    -- save the old values
            c1y=c1.y
            c1lv=c1.linearVelocity
            c1:destroy()    -- destroy the current object
            c1 = physics.body(CIRCLE,rad)  -- create a new object 
            c1.x=c1x     -- use old values
            c1.y=c1y   
            c1.linearVelocity=c1lv        
        end
    end                
end

Thanks Dave. Destroying and recreating seemed like the only option.

@Marksolberg

I’m going to try adding this for 1.5.

I’ve added this feature for the next release and confirmed that it does work even when setting the radius every frame.