-- PhysicsProj
-- Use this function to perform your initial setup
function setup()
w1 = physics.body(EDGE, vec2(0,0), vec2(WIDTH, 0))
w2 = physics.body(EDGE, vec2(0,0), vec2(0, WIDTH))
w3 = physics.body(EDGE, vec2(WIDTH, 0), vec2(WIDTH, HEIGHT))
linedestroy = true
balls={}
balls= CreateBall()
end
function CreateBall()
local p = physics.body(CIRCLE,50)
p.restitution = .8
p.linearVelocity = vec2(math.random(100,400), math.random(100,400))
p.x = math.random(60,250)
p.y = math.random(400,600)
p.color = color(math.random(0,255), math.random(0,255), math.random(0,255),100)
return p
end
function touched(t)
if t.state == BEGAN and not tw then
if CurrentTouch.x < otherx1 and CurrentTouch.x > otherx2 then
print("Success! Detected physics object.")
else
if linedestroy == true then
print("Touch not in area of physics object. Initializing garbage collection.")
w1:destroy()
linedestroy = false
end
end
if t.state == ENDED then
p:destroy()
p = nil
end
end
end
function draw()
-- This sets a dark background color
background(220)
pushStyle()
fill(255,255,0)
fill (balls.color)
ellipse(balls.x, balls.y, 100)
popStyle()
otherx1 = balls.x + 45
otherx2 = balls.x - 45
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
end
Hey guys. I’ve been having trouble with the :destroy() recently. I’ve been screwing with physics and I wanted to test out garbage collection with simple shapes. I do p:destroy(), while p is a physics body, call it, nothing happens. End the touch, the ball still appears as it sinks towards the bottom.
(The code is at the end of the touch function.) Help?
(No errors.)