I am trying to develop maze game using objective-c, I want to allow moving the pac-man using swipe method, the user can swipe his fingers on the iPhone to indicate where he want PAC-MAN to go but I'm stuck on moving pac_man. I used UIPanGesture but it can't indicate the collision of ghosts?

Please see the bellow code:

- (IBAction)pacmanmovement:(UIPanGestureRecognizer *)sender {
    CGPoint netTranslation;
    CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.pacman];

    sender.view.transform = CGAffineTransformMakeTranslation(
        netTranslation.x +  translatedPoint.x, 
        netTranslation.y += translatedPoint.y);

    if ([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
        netTranslation.x += translatedPoint.x;
        netTranslation.y += translatedPoint.y;

    [self collisionWithGhosts];

- (void)collisionWithGhosts {

    CALayer *ghostLayer1 = [self.ghost1.layer presentationLayer];
    CALayer *ghostLayer2 = [self.ghost2.layer presentationLayer];
    CALayer *ghostLayer3 = [self.ghost3.layer presentationLayer];
    CALayer *ghostLayer4 = [self.ghost4.layer presentationLayer];

    if (CGRectIntersectsRect(self.pacman.frame, ghostLayer1.frame)
        || CGRectIntersectsRect(self.pacman.frame, ghostLayer2.frame)
        || CGRectIntersectsRect(self.pacman.frame, ghostLayer3.frame)
        || CGRectIntersectsRect(self.pacman.frame, ghostLayer4.frame) ) {

        self.currentPoint  = CGPointMake(0, 144);

Any help?

  • \$\begingroup\$ Your question is not very straightforward. You have a problem with getting the swipe motion, moving the pac-man or checking for collisions ? \$\endgroup\$ – dimitris93 Aug 3 '15 at 20:53
  • \$\begingroup\$ Thank you Shiro for reply, my problem is the pac- man doesn't check collision with ghosts. \$\endgroup\$ – Fad Aug 5 '15 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.