mrl72

Jan 22, 2011, 02:59 PM

Not neccessarily Objective-C related, although the end goal is to have that, this is more of a brain teaser if you like! A virtual pint goes to the person who solves it! :)

I'm working on an app that displays "tiles" (basically images on buttons 190x190 pixels) in a grid that is 4 tiles wide by infinite deep, on a UIScrollView with vertical scrolling only. Each tile needs to be created at runtime and added in a sequential order, ie row 0 1 thru 4, row 2 1 thru 4 etc. I have everything working great, no problems. Saying that, I now want to include tiles that are 2x2 tiles in size added in the same sequential order, but I need to calculate the correct x & y positions of the smaller tiles that are added around it so they don't overlap. So if the 2x2 tile lands at column 3 & 4 on row 1, then the next two tiles should be added to rows 2, column 1 & 2 then the next 9 thru 12. In some cases a large tile might only appear once, or not at all. And the large tiles can only appear starting in columns 1 or columns 3, not in the middle and they can appear side by side (as in example below).

So I've been racking my brain on this for the past two days and have not come up with anything substantial without creating messy if..then logic, so ideally this needs to go into a method that I would call and it would just give me the x and y coordinates back of where to put the next small tile if a larger tile is occupying the space next to it. I was thinking by giving each tile a sequential number I can determine what numbers the larger ones take up and use that in an array or something. That way I can figure out what tile space is not occupied, but from there..... staring at ceiling....emptiness. I'm not a math expert so suspect there's some easy formula I can use, at least that's what I hope! :)

http://loughers.smugmug.com/photos/1164538831_AyJsM-XL.jpg

Cheers.

I'm working on an app that displays "tiles" (basically images on buttons 190x190 pixels) in a grid that is 4 tiles wide by infinite deep, on a UIScrollView with vertical scrolling only. Each tile needs to be created at runtime and added in a sequential order, ie row 0 1 thru 4, row 2 1 thru 4 etc. I have everything working great, no problems. Saying that, I now want to include tiles that are 2x2 tiles in size added in the same sequential order, but I need to calculate the correct x & y positions of the smaller tiles that are added around it so they don't overlap. So if the 2x2 tile lands at column 3 & 4 on row 1, then the next two tiles should be added to rows 2, column 1 & 2 then the next 9 thru 12. In some cases a large tile might only appear once, or not at all. And the large tiles can only appear starting in columns 1 or columns 3, not in the middle and they can appear side by side (as in example below).

So I've been racking my brain on this for the past two days and have not come up with anything substantial without creating messy if..then logic, so ideally this needs to go into a method that I would call and it would just give me the x and y coordinates back of where to put the next small tile if a larger tile is occupying the space next to it. I was thinking by giving each tile a sequential number I can determine what numbers the larger ones take up and use that in an array or something. That way I can figure out what tile space is not occupied, but from there..... staring at ceiling....emptiness. I'm not a math expert so suspect there's some easy formula I can use, at least that's what I hope! :)

http://loughers.smugmug.com/photos/1164538831_AyJsM-XL.jpg

Cheers.