开发者

CGRectIntersectsRect Problem

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 = [[开发者_如何学Goevent 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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜