iphone - Detect collision between multiple UIImageViews that are animated with the same name -



iphone - Detect collision between multiple UIImageViews that are animated with the same name -

i trying observe collision between falling/animated uiimageview created every sec nstimer. here's code:

-(void)newobject{ int randomx = 76+ arc4random() %(290); int randomduration = 2+ arc4random() %(6); int randomimage = 1+ arc4random() %(3) ; newobject = [[uiimageview alloc] initwithframe:cgrectmake(randomx,0,36 ,36)]; uiimage *imag = [uiimage imagenamed:@"ball.png"]; [newobject setimage:imag]; [self.view addsubview:newobject]; numberofobjects += 1; newobject.tag = numberofobjects; [uiview beginanimations:nil context:nil]; [uiview setanimationduration:randomduration]; [uiview setanimationbeginsfromcurrentstate:yes]; [uiview setanimationdelegate:self]; [uiview setanimationdidstopselector:@selector(animationdone:finished:context:)]; newobject.frame = cgrectmake(randomx, 300,newobject.frame.size.width,newobject.frame.size.height); [uiview commitanimations]; }

that code crates new uiimageview name newobject , animates downwards screen. observe collision have nstimer called every 1.0/60. here's code:

-(void)collison{ (int = 1; < numberofobjects; i++) { uiimageview *image = newobject; [image viewwithtag:i]; calayer *layer = image.layer.presentationlayer; cgrect newobjectframe = layer.frame; calayer *layer2 = sprint.layer.presentationlayer; cgrect sprintframe = layer2.frame; if (cgrectintersectsrect(newobjectframe, sprintframe)) { [self stoptimers]; nslog(@"hello"); } } }

the problem console says "it works" uiimage didn't collide , can collide character image console says nil , @ same time if seek collide character uiimageview works. i'am trying it's not reliable. can help?

update: edited code detecting lastly uiimageview added.

ok got it. it's simple need create nsmutablearray , check array collision loop.

iphone cocoa-touch uiimageview collision-detection

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -