CGRectIntersects矩形问题

发布于 2024-11-24 01:32:10 字数 659 浏览 5 评论 0原文

我正在制作一个带有迷宫的应用程序,我在界面生成器中将一个球放在迷宫内(我为它放置了一个出口)我有一个 TouchMoved:

 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint point;
point = [touch locationInView:self.view];

ball.center = point;

if (CGRectIntersectsRect(ball.frame, maze.frame)) {
   //my stuff
}


   }

我有两个 CGRectIntersectsRect if 语句,我说,如果球的框架接触迷宫的框架框架,然后//我的东西发生了,但由于某种原因,每当我尝试移动球,而不接触迷宫的框架,//我的东西就会发生。我不知道为什么,也许是因为球在迷宫中,可能不是因为我说如果 cgrectintersectsrect 框架没有边界。那么为什么会发生这种情况呢?

我有另一个名为 flag 的 uiimageview iboutlet,我有相同的 cgrectintersectsrect 类型的代码,并且它在相同的 TouchMoved 中工作,那么为什么这不起作用

I am making a app with a maze, I put a ball inside the maze in the interface builder (I put an outlet for it) I have a touchesMoved:

 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint point;
point = [touch locationInView:self.view];

ball.center = point;

if (CGRectIntersectsRect(ball.frame, maze.frame)) {
   //my stuff
}


   }

I have two CGRectIntersectsRect if statements, I say, if the ball's frame touches the maze's frame, then // my stuff happens, but for some reason, whenever i try to move the ball, without touching the frame of the maze, // my stuff happens. I dont know why, maybe it is because the ball is IN the maze, probably not because i said if cgrectintersectsrect frame not bounds. so why is this happening?

I have another iboutlet of a uiimageview called flag, i have the same cgrectintersectsrect type of code, and it works in the same touchesMoved, so why does this not work

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

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

发布评论

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

评论(1

甜是你 2024-12-01 01:32:10

试试这个

UITouch *touch = [[event allTouches] anyObject];

CGPoint point;

point = [touch locationInView:self.view];


point = [[CCDirector sharedDirector] convertToGL: point];


if (CGRectIntersectsRect(ball.bounds, maze.bounds)) {


//frame - x,y,w,h

//bounds- w,h

try this one

UITouch *touch = [[event allTouches] anyObject];

CGPoint point;

point = [touch locationInView:self.view];


point = [[CCDirector sharedDirector] convertToGL: point];


if (CGRectIntersectsRect(ball.bounds, maze.bounds)) {


//frame - x,y,w,h

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