I wanted to do something similar to the following thread:
http://www.iphonedevsdk.com/forum/ip...id-images.html
I'm not actually sure how best to explain this. Basically I'm in the process of creating an Arkanoid clone type game where there are several bricks on the screen. A ball bounces around the screen bumping off walls and when it finally collides with the paddle (controlled by the user) it changes velocity and eventually hits one of the bricks that appears above. So far this portion of the game has been completed.
I have 9 different colored images/bricks named (yellow.png, red.png, blue.png, etc).
What I wanted to do for each level is change the position of the bricks depending on the following (as an example of one of the levels) might be the following:
brickArray *brickLevel1 = {
{0,0,0,0,0,0,0,0},
{1,1,0,0,0,0,1,1},
{1,0,1,0,0,1,0,1},
{1,0,2,0,0,2,0,1},
{1,0,2,0,0,2,0,1},
{1,0,1,0,0,1,0,1},
{1,1,0,0,0,0,1,1},
{1,1,3,1,1,3,1,1}
};
The following is a representation of an 8x8 grid of bricks.
The "x" will be replaced with a number (as seen above) and then the number will be associated with a unique colored brick. The numbers range from 1 - 9.
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
[x] [x] [x] [x] [x] [x] [x] [x]
I am wanting to loop through this array and dynamically fill the correct image in its place depending on the brickLevel1 array?
The following is the current loop I'm using to display an 8x8 grid with just ONE color, because that's all I'm capable of doing at the moment. I wasn't sure how to implement my idea properly and loop through and render each image in its correct place.
Code:
Code:
int x = 0, y = 0, brick_width = 39, brick_height = 23;
for (int i=0; i < 64; i++)
{
x = (brick_width+1)*floor(i%8);
y = (brick_height+1)*floor(i/8);
brick = (UIImageView *)[brickArray objectAtIndex:i];
brick = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"yellow.png", i]]];
brick.transform = CGAffineTransformMakeTranslation(x, y);
if (CGRectIntersectsRect(ball.frame, brick.frame))
ballVelocity.y = -ballVelocity.y;
[self.view addSubview:brick];
}
I hope some of what I'm trying to achieve makes sense. If anyone could lead me in the right direction that would be greatly appreciated.