简体   繁体   中英

collision between two images

I have two images image1 and image2 and I want to "do something"when they collide, but I don't know the code for the collision and if we need a timer for the collision method. How can I do this please?

if you schedule a timer to serve as a runloop

[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(myRunloop) userInfo:nil repeats:YES];

and then in that runloop you check for collisions

- (void)myRunloop
{
    // check collision
    if( CGRectIntersectsRect(image1.frame, image2.frame) )
    {
        // ..do your stuff.. //
    }
}

you're done:-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM