Hi all,
I just started using this great SDK and have a question how to handle the access to a group which is stored in a table (array).
Basically I want to achieve something like this:
I have a 2 dimensional array with 8x8 field like a chess board.
For every field I create a display group containing all possible images for the figures (like tower, king, queen, etc.)
That looks like this:
local pawns = {}
for x = 1, 8 do
for y = 1, 8 do
local group = display.newGroup()
local pawn1 = display.newImage( "p1.png" )
group:insert( pawn1 , true )
local pawn2 = display.newImage( "p2.png" )
group:insert( pawn2 , true )
pawn2.isVisible = false -- make it invisible
-- and so on...
group:addEventListener( "touch", buttonListener )
group.x = (x-1) \* 40+20
group.y = (y-1) \* 40+20
pawns[x+(y-1)\*8] = group
Then I have my listener which looks like this:
local buttonListener = function( event )
if( event.phase == "ended" ) then
-- which group was touched?
local group = event.target
if( group[1].isVisible ) then
-- some actions here
elseif( group[2].isVisible ) then
-- some actions here
-- and so on...
What I like to achieve: I want to change the image of a neighbor field when touching a field. For example: I touch on field [1][1] and would like to change the image of field [1][2]… So how could I access other groups via my field?
I thought it would work this way:
pawns[7].group[2].isVisible = true
First of all: Is this a good way of doing it anyway or am I trapped into the wrong way here?
Here a short drawing to show what I mean (if my explanations are somewhat confusing).
Imaging a field of 4x4:
xxxx
xxxx
xxxx
xxxx
Now I click on field [1][1] and want to change this field as well as the neighbor field. So now it should look like this:
ooxx
xxxx
xxxx
xxxx
THANKS! [import]uid: 11180 topic_id: 5807 reply_id: 305807[/import]