Ok so I found this code on the internet and it’s pretty cool. I was trying to add an accelerometer to it, but when ever I try to spawn a ball I get an error. Anyone know why this happens?
function setup()
displayMode(FULLSCREEN)
--myFPSReporter = FPSReporter(4)
noSmooth()
balls = {}
touches = {}
base = physics.body(EDGE, vec2(100,0), vec2(WIDTH-100,0))
nextball = 0
end
function touched(touch)
if touch.state == ENDED then
touches[touch.id] = nil
else
--if touches[touch.id] == nil then
touches[touch.id] = touch
--end
end
end
function touchActions()
for k,v in pairs(touches) do
if CurrentTouch.state == ENDED then
--if there are no current touches then we kill all current touches to avoid bugged ball producers
touches[k] = nil
else
--add a new ball at the touch location
size = math.random(1,20)
tspot = physics.body(CIRCLE, size)
tspot.position = vec2(v.x+math.random(-1,1), v.y+math.random(-1,1))
tspot.restitution = 1
balls[nextball] = { tspot = tspot, size = size * 2, r = math.random(30,255), g = math.random(30,255), b = math.random(30,255) }
nextball = nextball + 1
end
end
end
function draw()
background(0, 0, 0, 255)
--myFPSReporter:draw(3)
strokeWidth(0)
for k,v in pairs(balls) do
if v.tspot.x < -20 or v.tspot.x > WIDTH + 20 or v.tspot.y < -20 then
balls[k].tspot:destroy()
balls[k] = nil
else
fill(v.r, v.g, v.b, 255)
ellipse(v.tspot.x, v.tspot.y, v.size)
x=x+Gravity.x*10
y=y+Gravity.y*10
end
end
touchActions()
end