calculate object radius

hi,

I have a physical circle that has a transition. I want to calculate its radius at a certain point of the transition (when the touch event is cancelled) so I can make an exact copy of it.

I’ve tried doing object.width/2 but the transition screws it up…

is there a way to calculate it? or perhaps copy the object somehow?

thank you…

You have to set the circle’s radius when creating a circle (presuming you’re using display.newCircle?); so simply store that value as a property of the display object, e.g:

local circle = display.newCircle(100,100,10)

circle.radius = 10

Not entirely sure if that’s what you’re after, but if you post some code I’m sure we’ll get there.

I need a variable that can change according to the object’s radius, which is changing all the time…

this is the code

function newBall(ref)
bT={}
refY=ref.y-70
ball=display.newCircle(ref.x, refY,20)
ball.alpha=0.5
ball:setReferencePoint(display.CenterReferencePoint)
physics.addBody(ball, “static”, {isSensor=true})
 

–this is the part where I transition the original circle
function ballIncrease()
tweenReference =  transition.to( ball, {time=2000, xScale=9, yScale=9} )
end

function ballReturn()
    transition.to( ball, {time=100,xScale=1, yScale=1} )
    transition.cancel(tweenReference)    
end

function removeBallref()
for i = #bT, 1, -1 do
        local object = bT[i]
        local child = table.remove(bT, i)    
            if child ~= nil then
                child:removeSelf()
                child = nil
                end
            end
end

 
function ballRef(ball)
bx=ball.x
by=ball.y
ballref=display.newCircle(bx,by,ballRad) --this is the part where i create the circle reference and need its radius

ballref.myName=“ball”
ballref.alpha=0.5
table.insert(bT,ballref)
physics.addBody(ballref,“static”, {isSensor=true})
ballref.myName=“ball”
return ballref
end

function onTouch( event )
    if(event.phase == “began”)then
    ballIncrease()
    elseif (event.phase == “ended” or event.phase == “cancelled”) then
    ballReturn()
    ballRef(ball)
    timer.performWithDelay(30,removeBallref)
end
end

Runtime:addEventListener( “touch”, onTouch )
return ball
end

object.width doesn’t seem to change with scale. It stays static at the original size. object.contentWidth changes according to the scaling. Try using that.

You have to set the circle’s radius when creating a circle (presuming you’re using display.newCircle?); so simply store that value as a property of the display object, e.g:

local circle = display.newCircle(100,100,10)

circle.radius = 10

Not entirely sure if that’s what you’re after, but if you post some code I’m sure we’ll get there.

I need a variable that can change according to the object’s radius, which is changing all the time…

this is the code

function newBall(ref)
bT={}
refY=ref.y-70
ball=display.newCircle(ref.x, refY,20)
ball.alpha=0.5
ball:setReferencePoint(display.CenterReferencePoint)
physics.addBody(ball, “static”, {isSensor=true})
 

–this is the part where I transition the original circle
function ballIncrease()
tweenReference =  transition.to( ball, {time=2000, xScale=9, yScale=9} )
end

function ballReturn()
    transition.to( ball, {time=100,xScale=1, yScale=1} )
    transition.cancel(tweenReference)    
end

function removeBallref()
for i = #bT, 1, -1 do
        local object = bT[i]
        local child = table.remove(bT, i)    
            if child ~= nil then
                child:removeSelf()
                child = nil
                end
            end
end

 
function ballRef(ball)
bx=ball.x
by=ball.y
ballref=display.newCircle(bx,by,ballRad) --this is the part where i create the circle reference and need its radius

ballref.myName=“ball”
ballref.alpha=0.5
table.insert(bT,ballref)
physics.addBody(ballref,“static”, {isSensor=true})
ballref.myName=“ball”
return ballref
end

function onTouch( event )
    if(event.phase == “began”)then
    ballIncrease()
    elseif (event.phase == “ended” or event.phase == “cancelled”) then
    ballReturn()
    ballRef(ball)
    timer.performWithDelay(30,removeBallref)
end
end

Runtime:addEventListener( “touch”, onTouch )
return ball
end

object.width doesn’t seem to change with scale. It stays static at the original size. object.contentWidth changes according to the scaling. Try using that.