Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1) ImageCache is not a standard class, so the class must be defined somewhere in the game's project. You are missing an <code>import "ImageCache.h"</code> (or whichever header file ImageCache is defined in).</p> <p>2) First, the <code>count</code> modulo 4 is taken. That is: divide <code>count</code> by 4 and take the rest. That rest is used as an index to brickTypes. So you will always get a value between 0 and 3 (including). Then, count is increased by 1 (the postfix ++ operator first returns the variable value and afterwards increases the variable by one). Since <code>brickType</code> seems to of type <code>NSString *brickType[4]</code> (you haven't showed us the declaration) this code will always return a string <code>@"bricktype1.png"</code> ... <code>@"bricktype4.png"</code>.</p> <p>3) I don't understand that question, sorry. Please try to explain.</p> <p>4) First, the position and size of the brick are queried (line 3). Then, the position is changed, while leaving the size unmodified (line 4). Lastly, the changed position and size are assigned to the brick. In effect, this just moves the brick to a new position. It must be done this way because <code>frame</code> is property of type CGRect (that is: it's a method called <code>setFrame:(CGRect)rect</code> but the compiler provides a more convenient way to access it) which is a struct containing other structs, so one can't just do <code>brick[x][y].frame.origin.x = x * 64</code>.</p> <p>5) It assigns a new position to the brick (or rather, to the struct queried from the brick). The <code>CGPointMake(x,y)</code> method returns a struct of type <code>CGPoint</code>. The result is assigned to the <code>frame</code>'s member <code>origin</code>. One could also write:</p> <pre><code>newFrame.origin.x = x * 64; newFrame.origin.y = (y * 40) + 50; </code></pre> <p>(here you can directly do the assigns because newFrame is a struct on your stack, not a method like <code>brick[x][y].frame</code>)</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.
    1. COThanks for your clear explanations. I understood the purpose in line 3-5 now. But in 4, `newFrame.origin` has given new co-ordinate to the `CGPointMake(x * 64, (y * 40) + 50);` why still need line 5? code. Also, in your explaination starting "It must be..." I am really confused, especially `which is a struct containing other structs` and I am totally lost in your reply 5). Could you make a graphically explanation or some code example?
      singulars
    2. CO`frame` returns a CGRect. That's defined as: struct CGRect { CGPoint origin; CGSize size; }; typedef struct CGRect CGRect; CGPoint and CGSize are again structs. So a CGRect is a struct, and it contains two other structs, origin and size. Now, `[foo frame]` and `[foo setFrame:bar]` only know about CGRect, but not CGRect's origin and size. This means that you first need to copy the CGRect (line 3). You can then modify that copy (line 4). But `newFrame` doesn't know about the change yet, so you need to pass the modified copy back to `newFrame` which is done in line 5.
      singulars
    3. COSee CGRect definition: http://iphonedevelopertips.com/c/cgrect-cgsize-and-cgpoint.html It contains a CGPoint and CGSize which are again structs. But the "package" (CGRect with origin + size) is just ONE memory area, and only this can be copied or modifed. Now, `[foo frame]` and `[foo setFrame:bar]` can copy CGRects, but not parts of it (CGRect's origin and size). This means that you first need to copy the CGRect (line 3). You can then modify that copy (line 4). But `newFrame` doesn't know about the change yet, so you need to pass the modified copy back to `newFrame` which is done in line 5.
      singulars
 

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