[resolved] Linking Display Object.

tl;dr : Can I store a reference to a display object as a property in another display object?

Hi all,

I’m developing a word search like puzzle for one of my games. I have a tiled board, where each tile is its own display object and associated mask, with letters displayed on top of each tile, which are obviously text objects. ie not part of the tile image at all.

At the moment I have three display groups which represent the game board. I have a tiles group, which contains all the tiles for the board in their correct positions. I have a letters group, which contains all the letters in their correct position above each tile. And finally I have the board group which is just a parent group for both tiles and letters to sit in so its easy to move the board if needed.

One of the mechanics I have implemented is that when the player touches a tile it turns green (a different image) to show it has been selected. The player then drags their finger to select 3 additional tiles to make up the complete word (sticking to 4 letter word until its functional). I have the tile selecting mechanic working fine, my problem is relating the selected tile to the letters which are sitting on top of it.

The way I was hoping to overcome this was by just storing a reference to the text object as a property in my tile object ie

aTile.letter = aLetter

but this doesnt seem to be working. Is this even possible or am I just doing it wrong? It seems to me that there should be no problem doing this as I’m just passing a reference to a table into a spot in another table right?

Another solution I thought of was instead of splitting the tiles and letters into two groups I could just make the tiles themselves a group. a tile group would contain a tile image and its corresponding letter, but I think this could get pretty messy in the long run.

Any ideas about the object reference thing or shall I just bite the bullet and go with the tile grouping idea? Any other suggestions are most welcome! [import]uid: 134131 topic_id: 26991 reply_id: 326991[/import]

That should work.

If your using a 2d array/matrix to represent your board you should be able to access that property like

board[x][y].letter [import]uid: 84637 topic_id: 26991 reply_id: 109517[/import]

Derp! found my mistake.

When I was replacing tiles with green tiles I wasnt transfering the .letter property to the new tile.

Hurrr

Thanks Danny! [import]uid: 134131 topic_id: 26991 reply_id: 109648[/import]

Your welcome :slight_smile: [import]uid: 84637 topic_id: 26991 reply_id: 109660[/import]