Hi guys. I was working a golf game interface, and the problem I’m encountering is very very strange. It only lets me click the first button that was drawn. It won’t let me click the other ones. It never plays the sound. But it draws all the buttons correctly. Here is the code:
supportedOrientations(LANDSCAPE_ANY)
function setup()
displayMode(FULLSCREEN)
buttons = {
{
X = 280;
Y = HEIGHT / 2;
locked = false;
};
{
X = 390;
Y = HEIGHT / 2;
locked = true;
};
{
X = 500;
Y = HEIGHT / 2;
locked = true;
};
{
X = 610;
Y = HEIGHT / 2;
locked = true;
};
}
atMenu = true
tapVar = nil
end
function collision(x,y,xSize,ySize,touchX,touchY)
if touchX > (x) and touchX < (x + xSize) and touchY > (y) and touchY < (y + ySize) then
sound("Game Sounds One:Pop 2")
end
end
function touched(tap)
if tap.state == BEGAN then
tapVar = tap
elseif tap.state == ENDED then
tapVar = nil
end
end
function draw()
background(255, 255, 255, 255)
if atMenu then
font("Futura-CondensedMedium")
fontSize(36)
fill(0, 0, 0, 255)
text("Golf Days",WIDTH / 2,HEIGHT - 75)
for i,v in pairs(buttons) do
if v.locked then
fill(255, 0, 9, 255)
else
fill(54, 255, 0, 255)
end
strokeWidth(4)
stroke(0, 0, 0, 255)
rect(v.X,v.Y,97,50)
fontSize(16)
font("Zapfino")
fill(0, 0, 0, 255)
text("Hole "..i,v.X + 46,v.Y + 20)
if tapVar then
collision(v.X,v.Y,97,50,tapVar.x,tapVar.y)
tapVar = nil
end
end
end
end