I would like to include a pause button in my application.
This is my application:
amount = math.random(10,350)
p={}
ps = amount
supportedOrientations(ANY)
function setup()
displayMode(FULLSCREEN)
for i=0,ps do
p[i]= {x=math.random(WIDTH*12)/12,
y=math.random(HEIGHT*8)/8, ox=0.0, oy=0.0, vx=math.random(20)-10,
vy=math.random(20)-10}
end
colors = {color(255, 255, 255, 255), color(0, 237, 255, 255),color(255, 0, 212, 255),color(76, 248, 15, 255),color(20, 39, 245, 255),color(239, 255, 0, 255),color(245, 11, 3, 255) }
stcolor = colors[math.random(#colors)]
end
function draw()
noSmooth()
background(2, 2, 2, 255)
fill(255, 0, 160, 255)
stroke(stcolor)
strokeWidth(4)
for i=0,ps do
p[i].ox= p[i].x
p[i].oy= p[i].y
p[i].x = p[i].x + p[i].vx
p[i].y = p[i].y + p[i].vy
if p[i].x<0 then
p[i].x=0
p[i].vx= -p[i].vx
sound(SOUND_BLIT, 24216)
end
if p[i].y<0 then
p[i].y=0
p[i].vy= -p[i].vy
sound(SOUND_JUMP, 34327)
end
if p[i].x>WIDTH then
p[i].x=WIDTH
p[i].vx= -p[i].vx
sound(SOUND_JUMP, 16358)
end
if p[i].y>HEIGHT then
p[i].y=HEIGHT
p[i].vy= -p[i].vy
sound(SOUND_BLIT, 5520)
end
p[i].vx = p[i].vx*0.98
p[i].vy = p[i].vy*0.98
line(p[i].ox, p[i].oy, p[i].x, p[i].y)
end
end
function touched(t)
a=5
for i=0,ps do
d= (p[i].x-t.x)*(p[i].x-t.x) + (p[i].y-t.y)*(p[i].y-t.y)
d= math.sqrt(d)
p[i].vx = p[i].vx - a/d*(p[i].x-t.x)
p[i].vy = p[i].vy - a/d*(p[i].y-t.y)
end
end
I think in the function setup() I should set a Boolean to false and in function draw() I should have an if statement that states if the Boolean is false make a sprite of the pause button in the right hand corner and if it is true make the play counterpart button appear also in the right hand corner. In function touched(t) I would have another if statement that says that if the pause button is touched the Boolean would be set to true and the statement would also say that if the play button is pressed it would set the Boolean to false. If the Boolean is true the application would run but if it was false it would not run. If this how you are to do please post back my code with necessary corrections as I have trouble understanding what people tell me to do for I am ten and if this not how you do it please tell me what to do like make new classes or etcetera.