Question about physics objects set as sensors but are filtered out of colliding with each other

So, here is my dilemma.  I have objects that are display.newCircles that I am using for explosions.  they start small and increase to a max size, then they decrease in size and eventually get removed.  Scaling up and down of a circle is easy.  but its corresponding physics body cannot be scaled, it must be removed, and the recreated with an increasing or decreasing radius to match the circle.
 
that works great, until another explosion is created on the top of an existing one, or overlaps another one.  I thought using a collision filter set to not collide with itself would solve this problem…but it appears that its still colliding with each other for some reason because im getting the dreaded “physics.addBody() can not be called when the world is locked” error message.
 
here is the filter 
 
colfilter.jpg
 
[lua]local explosionFilter = { categoryBits = 1, maskBits = 6 }
local warheadFilter = { categoryBits = 2, maskBits = 25 }
local alienFilter = { categoryBits = 4, maskBits = 1 }
local cityFilter = { categoryBits = 8, maskBits = 2 }
local bunkerFilter = { categoryBits = 16, maskBits = 2 }[/lua]

[lua]function explosion:new( locX, locY )
local locX = locX
local locY = locY
local id = table.maxn( explosion ); id = id + 1 – tick the id

self = display.newCircle( cnGroup, locX, locY, maxExplosionRadius )
self:setFillColor( 1, 1, 1 ); self:setStrokeColor( aR, aG, aB )
self.strokeWidth = 4; self.xScale = 0.2; self.yScale = 0.2; self.id = id
self.name = “explosion”; self.targetType = “explosion”; self.set = 1

function self:detonation( )
if self then
gameLoop:removeLoop(self)

if self.b then
transition.cancel( self.b )
end
if self.c then
transition.cancel( self.c )
end

self:removeSelf( )
self = nil
end
end

function self:explosionCollision( )
– body
end
self.b = transition.scaleBy( self, { time=1000, xScale=1, yScale=1 } )
self.c = transition.scaleBy( self, { delay=1000, time=880, xScale=0.0001, yScale=0.0001 } )

physics.addBody( self, { radius=minExplosionRadius, isSensor=true, filter=explosionFilter } )
self.collision = self.explosionCollision; self:addEventListener( “collision”, self )

self.tickCount = 0
self.countingUp = true
self.countComplete = false

function self:tick(time)
rgbShifter(self)

if self.countingUp == true then
physics.removeBody( self )
physics.addBody( self, { radius=minExplosionRadius + self.tickCount * 2, isSensor=true, filter=explosionFilter } )
self.tickCount = self.tickCount + 0.5
if self.tickCount == 29 then
self.countingUp = false
end
elseif self.countingUp == false and self.countComplete == false then
physics.removeBody( self )
physics.addBody( self, { radius=minExplosionRadius + self.tickCount * 2, isSensor=true, filter=explosionFilter } )
if self.tickCount == 0 then
self.countComplete = true
end
self.tickCount = self.tickCount - 0.5
elseif self.countComplete == true then
physics.removeBody( self )
self:detonation()
end
end
gameLoop:addLoop(self)
table.insert( explosion, id, self )
end [/lua]

Hi @joemauke,

First thing: can you go back and properly indent your code? It’s difficult to read and the community/staff will be able to help you more easily if the code is readable.

Thanks,

Brent

Hi @joemauke,

First thing: can you go back and properly indent your code? It’s difficult to read and the community/staff will be able to help you more easily if the code is readable.

Thanks,

Brent