How can I manipulate or access an object in a tiles layout?

Hello.

After a week, I finally got a layout of tiles “diamond” shape.

like a checkerboard for chess but in an ISOMETRIC form

I use the newMask ( ) to stop touching the transparent corners

of my rectangle.

I use object.myID to make sure each tile has a different number

I use for i loop and for j loop so basically 2 functions make the entire

screen layout.

this is my entire code simple 8 diamonds…

local mask = graphics.newMask( "images/m1mask.png" ) local tiles = {} function createBoard1()         for i = 1, 2 do               for j = 1, 2 do          local aTile = display.newImageRect(sceneGroup, "images/m1.png", 128, 64 )          tiles[i] = aTile -- For efficient instead of multiple lookups.          aTile:setMask( mask )          aTile.isHitTestMasked = true                 aTile.x = 128\*(i-1)                      aTile.y = 64\*(j-1)          aTile.myID = (i-1) \* 2 + j -- not sure where your ids are coming from, so I did this          aTile.touch = onTouch          aTile:addEventListener( "touch" )       end        end end createBoard1() local tiles2 = {} function createBoard2()         for i = 2, 4 do               for j = 2, 4 do          local bTile = display.newImageRect(sceneGroup, "images/m2.png", 128, 64 )          tiles2[i] = bTile -- For efficient instead of multiple lookups.          bTile:setMask( mask )          bTile.isHitTestMasked = true               bTile.x = 128\*((i-1)-1.5)                      bTile.y = 64\*((j-1)-1.5)          bTile.myID = ((i-1)-1) \* 2 + j -- not sure where your ids are coming from, so I did this          bTile.touch = onTouch          bTile:addEventListener( "touch" )       end        end end createBoard2()

and I have the function to detect if it is 5 or 8 or 7

local function onTouch( self, event )     if( event.phase == "began" ) then         print("Touched: ", self.myID )            if (self.myID) == 4 then                print("is 4")            elseif (self.myID) == 7 then                print("is 7")            end -- end of the if (self.myID)     end     return end

And it works great!

I can touch each tile and it has a unique number, 1 — 8

QUESTION —


when I touch 4 it prints … “is 4”

so I know that one “IS” 4

but how can I make 4.alpha = .5

or transition.to(4, { time=100…})

or 4.rotation = 45

like that…

I use the

bTile[4].alpha = .5 but is not working

also this

bTile.myID[4].alpha = .5 – Not working

I don’t know how to do this


Thanks for all your help

I think with this much I can make a wonderful educational game

thanks…

Been a while since you posted this question but still.

I see that you are creating a variable btile to then insert into the table. I did this same thing in my current project and had problems. I dont remember what type of problems bc I fixed it by simply assigning the display object and all of its properties directly to the table[i][j].

One of these properties is the object name, which is (in my case) the type of block/tile it is when it is either generated or loaded from json files. 

HOWEVER:  A theory I have gained by reading your post is that you are, as I was, assigning a variable “btile” to the table… so maybe “table[3].btile.alpha” or “table[btile].alpha” would work? Idk pal best of luck though. My solution isn’t too efficient i suppose but i got me where I needed to go and I can come back to it if performance becomes a problem as my game continues to grow.

Been a while since you posted this question but still.

I see that you are creating a variable btile to then insert into the table. I did this same thing in my current project and had problems. I dont remember what type of problems bc I fixed it by simply assigning the display object and all of its properties directly to the table[i][j].

One of these properties is the object name, which is (in my case) the type of block/tile it is when it is either generated or loaded from json files. 

HOWEVER:  A theory I have gained by reading your post is that you are, as I was, assigning a variable “btile” to the table… so maybe “table[3].btile.alpha” or “table[btile].alpha” would work? Idk pal best of luck though. My solution isn’t too efficient i suppose but i got me where I needed to go and I can come back to it if performance becomes a problem as my game continues to grow.