UIImage question
Hi all,
I am creating a breakout style game with the paddle and rows of bricks above, the first hurdle I've hit is how to create the rows of bricks... Would I be correct in thinking that i need to create an NSArray of UIImages, one UIImage for each brick. Is there a memory limit to the number of UIImages you can create, as I may have 50 bricks on screen at any one time?
Sorry I know this is probably a dumb question!
Thanks
I am creating a breakout style game with the paddle and rows of bricks above, the first hurdle I've hit is how to create the rows of bricks... Would I be correct in thinking that i need to create an NSArray of UIImages, one UIImage for each brick. Is there a memory limit to the number of UIImages you can create, as I may have 50 bricks on screen at any one time?
Sorry I know this is probably a dumb question!
Thanks
You don't need an array of UIImages like that, no. You need an array of something which represents what kind of brick is that location. That can be an number, a character, a struct with multiple properties...
Say for instance you're using characters. A space ' ' would be mean there is no brick, an 'r' could mean it's a red brick, a 'b' could mean it's blue brick, etc.
If you use an array of structs, the struct could be something like
When you're drawing the playing field, you'd loop through all of your bricks, check whether or not they should be visible, map the color/type to some image or texture, and use that to draw it.
Just an example:
When you're drawing the bricks:
I'm not saying that any of this is exactly how you should do it or what I'd do, but this certainly a general approach you can use. It should stimulate some thought.
Hope that helps.
Say for instance you're using characters. A space ' ' would be mean there is no brick, an 'r' could mean it's a red brick, a 'b' could mean it's blue brick, etc.
If you use an array of structs, the struct could be something like
Code:
struct Brick {
uint8_t color; // numbers mapped to a color
uint8_t health; // how many hits remaining needed to destroy it
....
}When you're drawing the playing field, you'd loop through all of your bricks, check whether or not they should be visible, map the color/type to some image or texture, and use that to draw it.
Just an example:
Code:
UIImage * brickColorToImage[5];
brickColorToImage[0] = [[UIImage imageNamed:@"RedBrick"] retain];
brickColorToImage[1] = [[UIImage imageNamed:@"BlueBrick"] retain];
etcWhen you're drawing the bricks:
Code:
loop {
Brick * brick = bricks + brickIndex;
UIImage * brickImage = brickColorToImage[brick->color];
... draw using the image ...
}I'm not saying that any of this is exactly how you should do it or what I'd do, but this certainly a general approach you can use. It should stimulate some thought.
Hope that helps.
Thanks Seth - confusing stuff but I will try and digest, this beats mapping an IBOutlet
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Trouble with UIImage in a class | Jmcclane | 8 | 4,001 |
Sep 10, 2010 01:24 PM Last Post: Jmcclane |
|
| UIImage Dimensions? | Jmcclane | 6 | 4,366 |
Sep 2, 2010 06:27 PM Last Post: AndyKorth |
|

