Hey guys, I have this idea for a simple game. Basically a sprite appears in some random space on the screen, you have to tap it within a certain time or you lose. But I don’t know how to make a sprite disappear. The circles will just keep being made randomly in different spots
P.s.
This is off topic, but is there a way to search discussion on this forum? I find looking for answers difficult because I have go from page to page reading titles of question and seeing if they are the same question as me
Use the touched function to detect finger touches, and test if they are within the circles. If so, stop drawing them.
I think this question has been asked a few times in the past, because touching things to make them disappear is a fairly obvious idea for a touch device, but I’m not sure where to find those threads.
I suggest you do a little research on the touched function (there is a demo app about it) to get started.
function setup()
sprites={}
delay=2
timer=0
end
function draw()
timer = timer + DeltaTime
if timer>=delay then
delay = delay * 0.95
timer=0
newSprite()
end
background(0)
spriteMode(RADIUS)
for i=#sprites,1,-1 do
local sp=sprites[i]
sp.timer = sp.timer + DeltaTime
if sp.timer>=sp.delay then table.remove(sprites,i)return end
fill(sp.col)
ellipse(sp.pos.x,sp.pos.y,sp.rad)
end
end
function touched(t)
local tpos=vec2(t.x,t.y)
for i=#sprites,1,-1 do
local sp=sprites[i]
if tpos:dist(sp.pos)<sp.rad then--i have tapped the sprite
print("hit")
table.remove(sprites,i)
end
end
end
function newSprite()
table.insert(sprites,
{pos=vec2(math.random(0,WIDTH),math.random(0,HEIGHT)),timer=0,rad=math.random(20,50),
delay=math.random(1,4),col=color(math.random(255),math.random(255),math.random(255))})
end
Whack a mole for iPad? I haven’t seen anyone do a good one, go for it! Learn about touches in codea along with lua tables, these are the things you’ll be learning mostly.