c++ - Intersection between multiple images in Xcode -


hey guys have been making game in user presses button , every time presses button, screens adds new uiimageview (which same every time). these uiimageviews separately draggable uitouch function. want them detect intersection well! , want know 2 uiimageviews intersected can change image-url of 2 uiimageviews intersected.

-(ibaction)cltouched:(id)sender {  imgview2 = [[uiimageview alloc] initwithframe:cgrectmake(120, 20, 80, 80)]; imgview2.backgroundcolor = [uicolor clearcolor]; imgview2.userinteractionenabled = true; imgview2.image = [uiimage imagenamed:@"cl.png"];  [self.view addsubview:imgview2]; 

}

// move image touch can - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event { imgview.userinteractionenabled = true;

// touch event uitouch *touch = [[event alltouches] anyobject]; cgpoint touchlocation = [touch locationinview:self.view];  if ([self.view.subviews containsobject:[touch view]]) {     [touch view].center = touchlocation; }  if (cgrectintersectsrect(imgview.frame, imgview2.frame)) {     naam.text = @"intersection"; } 

}

i hope enough information me out!

you use cgrectintersectsrect() see if uiimageview intersecting another. example below..

edit: realized afterwards implemented cgrectintersectsrect() method. if have array of other images can access, while dragging said image want compare, can this

   for(uiimageview *image in yourarrayofimages) {           if(cgrectintersectsrect(self.frame,[image frame])) {                nslog(@"self overlaps %@",image);               //now know self overlapping `image`, change url.            }      } 

being have multiples of these images, have loop through images , use above method of determining image(s) intersecting.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -