Take the 2-minute tour ×

I have a game and I want that every time an image(image1) touchs another image(image2) a counter count one, if it touches a second time it becomes two. So it's something that counts. How can I do this?

share|improve this question

1 Answer 1

Is this a collision detection? This link may help... collision detection

So you may have to write a collision detection method. Then each time it collide, you increment the count.

- (BOOL)collisionCheck:(UIImage *)image1 withImage:(UIImage *)image2 {

    return CGRectIntersectsRect(image1.frame, image2.frame);

// then in game loop

// code that move the image here

if ([self collisionCheck:image1 withImage:image2] == YES) {

    // code that bounce the image here

share|improve this answer
I know how to use collision detection but I want is to count .How can I count the number of time that it collide ? –  arvin Arabi May 4 '11 at 14:32
The collision method you wrote could return a boolean. Then you just check if yes then increment the variable. Is that help? In your game loop, I think you check for collision every frame. –  Khomsan May 4 '11 at 14:58
is there sample code for this please ? –  arvin Arabi May 4 '11 at 14:59
I have added the code –  Khomsan May 4 '11 at 15:15
ok but can we use then the number of count for something else. Like if count =10 game finish ?? –  arvin Arabi May 4 '11 at 16:19

Your Answer


