-1

i have 10 bricks, whenever my ball hit one of them i want to remove that brick. (brick breaker)

That is what i tried

for (int bri=1; bri<11; bri++) {
//  NSObject *brickimg = [NSObject stringWithFormat:@"brick%d", bri];
//  if (CGRectIntersectsRect(ball.frame, brickimg.frame)) {
//      [UIImageView stringWithFormat:@"brick%d", bri].hidden = YES;
//  }
}

and also

UIImageView *brickimg = [UIImageView stringWithFormat:@"brick%d", bri];

but no chance. How is the correct Syntax ?

siniradam
  • 2,727
  • 26
  • 37

1 Answers1

0

How about calling stringWithFormat: on the correct class, which is NSString?

Eiko
  • 25,601
  • 15
  • 56
  • 71
  • UIImageView *brickimg = [NSString stringWithFormat:@"brick%d", bri]; if (CGRectIntersectsRect(ball.frame, brickimg.frame)) { NSLog(@"test"); } that is crashes – siniradam Dec 23 '10 at 12:16
  • Sorry, but I have the impression that you don't know at all what you're doing. If you want a UIImageView you can init one with an image which you retrieve with a name that you construct with stringWithFormat:. But then, this is most probably not what you want to do here anyway, as you want to check against already availably instances. – Eiko Dec 23 '10 at 12:25
  • your impression quite right. im just trying to get it. all i want to do getting avoid writing 10 times CGRectIntersectsRect(ball.frame, brick1.frame) .. 2 .. 3 – siniradam Dec 23 '10 at 12:43
  • I think Eiko was referring to your being clue impaired in the larger sense. No worries, we all started there. I'd suggest you (re)read the Objective-C guide provided in the documentation to gain a thorough understanding of Objects, Classes, and Methods. Then go from there. – bbum Dec 23 '10 at 16:49
  • Thanks for your common sense. I'll do that. Actually i'm reading O'really's iPhone Game Development. – siniradam Dec 24 '10 at 12:42