Note that there are some explanatory texts on larger screens.

plurals
  1. POCompiled Error in Xcode for iphone game and other questions
    primarykey
    data
    text
    <p>I am a newbie of xcode and objective-c and I have a few questions regarding to the code sample of a game attached below. It is written in objective C, Xcode for iphone4 simulator. It is part of the code of 'ball bounce against brick" game. Instead of creating the image by IB, the code supposes to create (programmatically) 5 X 4 bricks using 4 different kinds of bricks pictures (bricktype1.png...). I have the bricks defined in .h file properly and method written in .m.</p> <p>My questions are for the following code:</p> <pre><code>- (void)initializeBricks { brickTypes[0] = @"bricktype1.png"; brickTypes[1] = @"bricktype2.png"; brickTypes[2] = @"bricktype3.png"; brickTypes[3] = @"bricktype4.png"; int count = 0; for (int y = 0; y &lt; BRICKS_HEIGHT; y++) { for (int x = 0; x &lt; BRICKS_WIDTH; x++) { UIImage *image = [ImageCache loadImage:brickTypes[count++ % 4]]; - Line1 bricks[x][y] = [[[UIImageView alloc] initWithImage:image] autorelease]; CGRect newFrame = bricks[x][y].frame; newFrame.origin = CGPointMake(x * 64, (y * 40) + 50); bricks[x][y].frame = newFrame; [self.view addSubview:bricks[x][y]]; } } } </code></pre> <p>1) When it is compiled, error "ImageCache undeclared" in Line 1. But I have already added the png to the project. What is the problem and how to fix it? (If possible, please suggest code and explain what it does and where to put it.)</p> <p>2) How does the following in Line 1 work? Does it assign the element (name of .png) of brickType to image?</p> <blockquote> <p>brickTypes[count ++ % 4]</p> </blockquote> <p>For instance, returns one of the file name bricktype1.png to the image object? If true, what is the max value of "count", ends at 5? (as X increments 5 times for each Y). But then "count" will exceed the max 'index value' of brickTypes which is 3! </p> <p>3) In Line2, does the image object which is being allocated has a name and linked with the .png already at this line <strong>before</strong> it is assigned to brick[x][y]?</p> <p>4) What do Line3 and Line5 do? Why newFrame on left in line3 but appears on right in Line5?</p> <p>5) What does Line 4 do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload