I am attempting to generate a grid of images. Each image is 50x50 and when the loop is done it should, "theoretically" have created a 250x250 grid of the 50x50 images. But I can't get the images to show up. Can anyone see what I am doing wrong? Any ideas?
Please be as harsh as you need to, I can handle it.
Please be as harsh as you need to, I can handle it.
OK. You're an idiot. You shouldn't even be doing this. Get a job mowing lawns.
Just kidding of course but you did ask for it
There are several issues with this code. You are using the same image for each cell so why create it over and over? Just create the image once and reuse it.
You don't actually create any UIImageView objects. And even if you were you're not making any attempt to position them within your grid.
And you have a memory leak with each image since you keep retaining but never releasing.
And last, you're not adding the image view to the view.
Thanks for the quick response! I unfortunately just gave up that job of mowing yards to being my life as a programmer!
But anyway, that's kinda where I was going with the code. I just can't get it to display in the main window. I even went into interface builder and tried creating an UIImageView and making sure it was all linked together. This isn't the first program I have created. So I know I have got to be missing something really simple and stupid that I am overlooking that I just didn't connect.
OK. You're an idiot. You shouldn't even be doing this. Get a job mowing lawns.
Just kidding of course but you did ask for it
There are several issues with this code. You are using the same image for each cell so why create it over and over? Just create the image once and reuse it.
You don't actually create any UIImageView objects. And even if you were you're not making any attempt to position them within your grid.
And you have a memory leak with each image since you keep retaining but never releasing.
And last, you're not adding the image view to the view.
This code assume you want the same image in each spot in the grid. If not you need to change how the actual image is loaded.
And I just typed this in so no guarantee it's perfect.
Howdy, sorry to hijack this thread. But I wanted to do something similar to this.
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:
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.
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:
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.