0

我正在开发游戏。下面的屏幕截图显示了我的游戏的整个过程。 在此处输入图像描述

首先,当我的游戏开始时,在 viewdidload 中,我使用 NStimer 从上到下移动我的红球。当我点击我的 aeroplan 时,它首先是使用 NStimer 的 Missels...首先我检查交叉点然后创建新球。

          if ((CGRectIntersectsRect(missels.frame,Ball.frame))
         {
          [self performSelector:@selector(createball) ];
          }

当我的导弹击中球时,它分成两部分,如我在屏幕截图中显示的那样。这是这两个新球的代码。

 -(void)createball{
  imageMove1 = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,50 ,50)];        
  UIImage *imag = [UIImage imageNamed:@"ball1.png"];
  [imageMove1 setImage:imag];
  imageMove1.tag=i;
  [self.view addSubview:imageMove1];
  [ballArray addObject:imageMove1];

  imageMove2 = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,50 ,50)];        
  UIImage *imag1 = [UIImage imageNamed:@"ball1.png"];
  [imageMove2 setImage:imag1];
  imageMove2.tag=k;
  [self.view addSubview:imageMove2];
  [ball1Array addObject:imageMove2];
  [self performSelector:@selector(moveball) ];
 }

之后,我使用 CAKeyframeAnimation 将运动赋予这些新球。这里是代码。

-(void)moveball{
 for (int i=0; i<[ballArray count]; i++) {
 moveimg=[ballArray objectAtIndex:i];
 CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
 pathAnimation.calculationMode = kCAAnimationPaced;
 pathAnimation.fillMode = kCAFillModeForwards;
 pathAnimation.removedOnCompletion = NO;
 pathAnimation.duration = 15.0;
 pathAnimation.repeatCount = 1;
 CGMutablePathRef curvedPath = CGPathCreateMutable();
 CGPathMoveToPoint(curvedPath, NULL, x+15, y);
 CGPathAddQuadCurveToPoint(curvedPath, NULL, 20, 10, 100, 330);
 pathAnimation.path = curvedPath;
 CGPathRelease(curvedPath);
 moveimg.center=CGPointMake(x, y);
 [moveimg.layer addAnimation:pathAnimation forKey:@"moveTheSquare"];
  }

for (int k=0; k<[ball1Array count]; k++) {
        move1img=[ball1Array objectAtIndex:k];
        CAKeyframeAnimation *pathAnimation1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        pathAnimation1.calculationMode = kCAAnimationPaced;
        pathAnimation1.fillMode = kCAFillModeForwards;
        pathAnimation1.removedOnCompletion = NO;
        pathAnimation1.duration = 15.0;
        pathAnimation1.repeatCount = 1;
        CGMutablePathRef curvedPath1 = CGPathCreateMutable();
        CGPathMoveToPoint(curvedPath1, NULL, x+40, y);
        CGPathAddQuadCurveToPoint(curvedPath1, NULL, 350, 10, 380, 330);
        pathAnimation1.path = curvedPath1;
        CGPathRelease(curvedPath1);
        move1img.center=CGPointMake(x, y);
        [move1img.layer addAnimation:pathAnimation1 forKey:@"moveTheSquare"];
     }
   }

我的这种方法只对我在missels和球相交后创建前两个球有效。一旦我的球运动后,它不适用于相交。所以简而言之,在这场比赛中我面临两个主要问题。

  1. 如何在我的球和 Missels 的每个交叉点上创建两个新球。
  2. 创建这些球后,如何在与missel相交的移动过程中获取这些球的帧。就像这样..

      if ((CGRectIntersectsRect(missels.frame,mynewballs.frame))
    

    任何人都可以给出解决这个问题的最佳想法。任何帮助都将提前获得。thanx。

4

0 回答 0