I’m trying to make a simple game in codea and looking at the tutorial (under getting started) I’ve recreated the ball example that has the circle bounce around the screen. However, when the user flicks the ball near the edge of the screen the ball gets stuck to the side of the screen. Is there a way to fix this?
Here is the code from the tutorial that I need in my program:
function setup()
x = WIDTH/2
y = HEIGHT/2
bc = color(248, 250, 13, 255)
tc = color(195, 17, 17, 255)
c = bc
inTouch = false
dx = 0
dy = 0
r = 30
end
function draw()
background(0, 0, 0, 255)
fill(c)
ellipse(x,y,r)
if inTouch then
x = tx
y = ty
c = tc
else
x = x + dx
y = y + dy
c = bc
end
if y > HEIGHT - r then
dy = - dy
end
if y < r then
dy = - dy
end
if x > WIDTH - r then
dx = - dx
end
if x < r then
dx = - dx
end
end
function touched(touch)
tx = touch.x
ty = touch.y
if touch.state == BEGAN then
inTouch = true
velocity = {}
end
if touch.state == MOVING then
table.insert(velocity,1,vec2(touch.deltaX,touch.deltaY))
end
if touch.state == ENDED then
dx = 0
dy = 0
n = 0
for i = 1,10 do
if velocity[i] then
n = n + 1
dx = dx + velocity[i].x
dy = dy + velocity[i].y
end
end
if n >0 then
dx = dx / n
dy = dy / n
end
inTouch = false
end
end