Wednesday, 15 May 2013

objective c - Collision Being Detected before Collision Takes Place -



objective c - Collision Being Detected before Collision Takes Place -

in next code seek , observe if code detecting collision. before bullet , line collides, debugger says "collided!"

//collision detector -(bool)viewsdocollide { if(cgrectintersectsrect(_bullet.frame, _line.frame)) { homecoming yes; } else { homecoming no; } } //so turrets shoot - (ibaction)shooterbutton:(id)sender { [self mover:(id)sender]; } - (void)mover:(id)sender { cgrect bulletframe = _bullet.frame; cgrect lineframe = _line.frame; [uiview animatewithduration:2 animations:^{ cgrect newframe = cgrectmake(bulletframe.origin.x + lineframe.origin.x - 14, bulletframe.origin.y, bulletframe.size.width, bulletframe.size.height); _bullet.frame = newframe; }]; bool collisiondetector = [self viewsdocollide]; if (collisiondetector == yes) { nslog(@"collided!"); } }

i presume collision "taking place" before because have set position bullet. how "shoot" bullet without using [uiview animatewithduration]? or, how code observe collision when happens?

your collision detection code not within animation running. you've asked os animate 1 frame another, happen after function has returned (on ui thread).

so, you're detecting collisions before animation has started.

if want 2d game, recommend using cocos2d. has high-level back upwards want do.

objective-c collision-detection

No comments:

Post a Comment