The only problem is that i have 9 of those images and would like to figure out how to do that with unknown number of pics. I am just starting to learn and figured I should start with something simple like a tic tac toe game but from what i see it is not THAT simple lol anyone has a good tic tac toe tutorial? so far this is what i have but it ends the game randomly… sometimes even on the first click =/
[code]_H = display.contentHeight
_W = display.contentWidth
clicked = 0
–[middle row]–
local button22= display.newImage( “blank.png” )
button22.x = _W / 2
button22.y = _H /2
button22.state = “blank”
local button21 = display.newImage( “blank.png” )
button21.x = button22.x -100
button21.y = button22.y
button21.state = “blank”
local button23 = display.newImage( “blank.png” )
button23.x = button22.x +100
button23.y = button22.y
button23.state = “blank”
–[top row]–
local button11 = display.newImage( “blank.png” )
button11.x = button21.x
button11.y = button21.y - 100
button11.state = “blank”
local button12 = display.newImage( “blank.png” )
button12.x = button22.x
button12.y = button22.y -100
button12.state = “blank”
local button13 = display.newImage( “blank.png” )
button13.x = button23.x
button13.y = button23.y -100
button13.state = “blank”
–[bottom row]–
local button31 = display.newImage( “blank.png” )
button31.x = button21.x
button31.y = button21.y +100
button31.state = “blank”
local button32 = display.newImage( “blank.png” )
button32.x = button22.x
button32.y = button22.y +100
button32.state = “blank”
local button33 = display.newImage( “blank.png” )
button33.x = button23.x
button33.y = button23.y +100
button33.state = “blank”
local cross = display.newImage(“cross.png”)
cross.x = (display.contentWidth / 2) -50
cross.y = 100
local circle = display.newImage(“circle.png”)
circle.x = (display.contentWidth/2) +50
circle.y = cross.y
function endGame()
local endtxt = display.newText( “END GAME”, _W/2, _H/2, native.systemFont, 24 )
endtxt:setTextColor( 255,0,0 )
end
function changeToCross( event )
local button = event.target
if (button.state == “blank”) then
clicked = clicked + 1
button = display.newImage(“cross.png”)
button.x = event.target.x
button.y = event.target.y
end
if (clicked == 9) then
local endtxt = display.newText( “END GAME”, _W/2, _H/2, native.systemFont, 24 )
endtxt:setTextColor( 255,0,0 )
end
end
function changeToCircle( event )
local button = event.target
if (button.state == “blank”) then
clicked = clicked + 1
button = display.newImage(“circle.png”)
button.x = event.target.x
button.y = event.target.y
end
if (clicked == 9) then
local endtxt = display.newText( “END GAME”, _W/2, _H/2, native.systemFont, 24 )
endtxt:setTextColor( 255,0,0 )
end
end
function changeCross (event)
local button = event.target
button11:addEventListener(“touch”, changeToCross)
button12:addEventListener(“touch”, changeToCross)
button13:addEventListener(“touch”, changeToCross)
button21:addEventListener(“touch”, changeToCross)
button22:addEventListener(“touch”, changeToCross)
button23:addEventListener(“touch”, changeToCross)
button31:addEventListener(“touch”, changeToCross)
button32:addEventListener(“touch”, changeToCross)
button33:addEventListener(“touch”, changeToCross)
end
function changeCircle (event)
local button = event.target
button11:addEventListener(“touch”, changeToCircle)
button12:addEventListener(“touch”, changeToCircle)
button13:addEventListener(“touch”, changeToCircle)
button21:addEventListener(“touch”, changeToCircle)
button22:addEventListener(“touch”, changeToCircle)
button23:addEventListener(“touch”, changeToCircle)
button31:addEventListener(“touch”, changeToCircle)
button32:addEventListener(“touch”, changeToCircle)
button33:addEventListener(“touch”, changeToCircle)
end
cross:addEventListener(“touch”, changeCross)
circle:addEventListener(“touch”, changeCircle)[/code] [import]uid: 133512 topic_id: 23220 reply_id: 93424[/import]