gpt4 book ai didi

iphone - CGPathContainsPoint 问题?

转载 作者:行者123 更新时间:2023-12-03 21:23:52 26 4
gpt4 key购买 nike

这是在 GameViewController.m

-(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);

if(CGPathContainsPoint(fillPath, nil, "What goes here?", false)){
[self doDie];
}
else {
CGContextFillPath(gameViewObj._myContext);
}
CGPathRelease(fillPath);
[pointsToFillArray removeAllObjects];
}


}

这是在 GameView.m

-(CGPoint) GetBirdPosition:(CGPoint) PtPoint :(int) BirdNumber{
CGPoint Temp=PtPoint;
BOOL isTouch=TRUE;
while (isTouch)
{
isTouch=FALSE;
if(playField[(int) Temp.x][(int) Temp.y]==2)
{
isTouch=TRUE;
if(playField[(int) Temp.x+1][(int) Temp.y] == 2 || playField[(int) Temp.x-1][(int) Temp.y] == 2)
{
pos[BirdNumber].y = -pos[BirdNumber].y;
Temp.y+=pos[BirdNumber].y;

}
else if(playField[(int) Temp.x][(int) Temp.y+1] == 2 || playField[(int) Temp.x][(int) Temp.y-1] == 2)
{
pos[BirdNumber].x = -pos[BirdNumber].x;
Temp.x+=pos[BirdNumber].x;
}

}
}
return Temp;
}

-(void)flyingBird:(NSTimer *)timer {

if(appDelegate.gameStateRunning == YES){

for (int i=0; i< [birdImageViewArray count];i++)
{
UIImageView* birdImageView=[birdImageViewArray objectAtIndex:i];

CGPoint Temp=CGPointMake(birdImageView.center.x + pos[i].x , birdImageView.center.y + pos[i].y);
birdImageView.center =[self GetBirdPosition:Temp:i];

if(playField[(int) birdImageView.center.x][(int) birdImageView.center.y]==3){

[[NSNotificationCenter defaultCenter] postNotificationName:@"LineCrossed" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"PlayDieSound" object:nil];
}
}
}
}

我不知道我写的“这里有什么”的地方写了什么??我希望这样,如果一只鸟被困在形状内,就会发生 [doDie]。如果小鸟没有被困在形状内,它就会被填充。任何想法都将不胜感激。

最佳答案

我不太理解你的代码,但我想这基本上就是你想要做的:

CGPoint Temp=CGPointMake(birdImageView.center.x + pos[birdNum].x , birdImageView.center.y + pos[birdNum].y);
if(CGPathContainsPoint(fillPath, nil, [myGameView GetBirdPosition:Temp:i], false)){
[self doDie];
}

看起来你的路径最初只是一条线,我认为其中不会包含任何内容。如果您更彻底地解释目标(我们要检查多少只鸟?每只鸟的路径相同吗?)我们可以提供进一步帮助。

编辑:

嗯嗯,好的。第一件事很简单。如果路径中有任何鸟,为了防止填充,请勿使用 else 情况。在 if 中,如果当前鸟包含在路径中,则设置一个标志。然后在循环之后,如果未设置标志,则填充路径。所以类似:

BOOL pathContainsBird = NO;
for (int i=0; i<[pointsToFillArray count]; i++) {
//bunch of stuff
if(CGPathContainsPoint(fillPath, nil, "What goes here?", false)){
pathContainsBird = YES;
[self doDie];
}
}
if(!pathContainsBird) {
//fill path here
}

其次,我很确定您没有循环浏览正确的内容。看起来你每次迭代都会扩展路径,但我认为你应该首先构建整个路径,然后循环所有的鸟,但我可能会产生误解。

关于iphone - CGPathContainsPoint 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2263343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com