if语句质疑iphone?

发布于 2024-08-21 21:10:24 字数 882 浏览 7 评论 0原文

我正在创建一个游戏,您可以在其中完成形状并填充该区域。但是,如果您的形状内有一只敌鸟,则该区域不会填充。我想这样做,以便如果您确实将一只鸟困在您的形状内,则该区域将被填充。形状,你就会失去一条生命。我怎样才能写一个 if 语句,它几乎说明如果下面的代码没有发生,那么你就会失去生命。如果它有助于失去生命,则在我的代码中称为 doDie。

-(void)fillMutablePath{



 CGPoint movePoint = CGPointFromString([pointsToFillArray objectAtIndex:0]);

 CGPathMoveToPoint(fillPath, NULL, movePoint.x, movePoint.y);

 for (int i=0; i<[pointsToFillArray count]; i++) {
  CGPoint tempPoint = CGPointFromString([pointsToFillArray objectAtIndex:i]);
  CGPathAddLineToPoint(fillPath, NULL, tempPoint.x, tempPoint.y);

 }


 CGContextAddPath(gameViewObj._myContext, fillPath);
 CGContextFillPath(gameViewObj._myContext);
 CGPathRelease(fillPath);

 [pointsToFillArray removeAllObjects];

}

if(fillMutablePath doesn't take place when making a shape){
[self doDie];
}

就像我上面所说的, fillMutablePath 不会发生的原因是因为一只鸟会被困在形状内。任何帮助将不胜感激!

I am creating a game where where you complete shapes and the area gets filled in. However, if there is an enemy bird within your shape, it will not fill in. I want to make it so that if you do trap a bird within your shape, you will lose a life. How can I write an if statement that pretty much says if the below code doesn't take place, then you lose a life. If it helps losing a life is called doDie in my code.

-(void)fillMutablePath{



 CGPoint movePoint = CGPointFromString([pointsToFillArray objectAtIndex:0]);

 CGPathMoveToPoint(fillPath, NULL, movePoint.x, movePoint.y);

 for (int i=0; i<[pointsToFillArray count]; i++) {
  CGPoint tempPoint = CGPointFromString([pointsToFillArray objectAtIndex:i]);
  CGPathAddLineToPoint(fillPath, NULL, tempPoint.x, tempPoint.y);

 }


 CGContextAddPath(gameViewObj._myContext, fillPath);
 CGContextFillPath(gameViewObj._myContext);
 CGPathRelease(fillPath);

 [pointsToFillArray removeAllObjects];

}

if(fillMutablePath doesn't take place when making a shape){
[self doDie];
}

Like i said above, the reason fillMutablePath wouldn't take place is because a bird would be trapped within the shape. Any help would be much appreciated!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天煞孤星 2024-08-28 21:10:24

我不完全确定如何以及在哪里检查鸟是否在路径中。我认为在填充路径之前你应该做的事情(参见if-else):

-(void)fillMutablePath{

    CGPoint movePoint = CGPointFromString([pointsToFillArray objectAtIndex:0]);
    CGPathMoveToPoint(fillPath, NULL, movePoint.x, movePoint.y);
    for (int i=0; i<[pointsToFillArray count]; i++) {
       //...
    }
    CGContextAddPath(gameViewObj._myContext, fillPath);

   if(CGPathContainsPoint(fillPath, nil, bird.center, false)){
      [self doDie];
    }
   else {
      CGContextFillPath(gameViewObj._myContext);
    }
   CGPathRelease(fillPath);

   [pointsToFillArray removeAllObjects];
}

如果鸟在路径中就会死亡。不然就画吧

澄清后编辑:

   //...

   CGContextAddPath(gameViewObj._myContext, fillPath);
   CGContextFillPath(gameViewObj._myContext);

   if(CGPathContainsPoint(fillPath, nil, bird.center, false)){
      [self doDie];
   }
   CGPathRelease(fillPath);
   [pointsToFillArray removeAllObjects];
}

I'm not entirely sure how and where you check if the bird is in the path. I think that right before filling you path you should do (see that if-else):

-(void)fillMutablePath{

    CGPoint movePoint = CGPointFromString([pointsToFillArray objectAtIndex:0]);
    CGPathMoveToPoint(fillPath, NULL, movePoint.x, movePoint.y);
    for (int i=0; i<[pointsToFillArray count]; i++) {
       //...
    }
    CGContextAddPath(gameViewObj._myContext, fillPath);

   if(CGPathContainsPoint(fillPath, nil, bird.center, false)){
      [self doDie];
    }
   else {
      CGContextFillPath(gameViewObj._myContext);
    }
   CGPathRelease(fillPath);

   [pointsToFillArray removeAllObjects];
}

If the bird is in the path die. Else, draw.

Edit after the clarification:

   //...

   CGContextAddPath(gameViewObj._myContext, fillPath);
   CGContextFillPath(gameViewObj._myContext);

   if(CGPathContainsPoint(fillPath, nil, bird.center, false)){
      [self doDie];
   }
   CGPathRelease(fillPath);
   [pointsToFillArray removeAllObjects];
}
别想她 2024-08-28 21:10:24

该方法不能返回 BOOL 吗?

这样,如果鸟在形状中,该方法将返回 yes,如果鸟不在形状中,则返回 no。

然后您可以稍后在 if 中使用返回值。

Could the method not return a BOOL?

That way if the bird is in the shape, the method returns yes, and if the bird is not in the shape, it returns no.

Then you can use the return value in an if later on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文