在我的应用我想(用下面的代码从触摸)到移动对象的红色矩形内如何使这个如何使利润率
代码:
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:[touch view]];
if (insidethepaddle) {
object1.center = CGPointMake(location.x, location.y - 50);
}
在我的应用我想(用下面的代码从触摸)到移动对象的红色矩形内如何使这个如何使利润率
代码:
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:[touch view]];
if (insidethepaddle) {
object1.center = CGPointMake(location.x, location.y - 50);
}
只需使用CGRectContainsPoint(CGRect rect, CGPoint point)
或NSPointInRect(NSPoint aPoint, NSRect aRect)
来测试中心是否还在里面,否则就不要更新对象center
。
指定的CGRect
/NSRect
表示红色矩形的框架。
我使用了你的代码CGRect red = CGRectMake(40,80,300 ,440); \t如果(insidethepaddle && \t CGRectContainsPoint(红,位置)){ \t \t = paddle.center CGPointMake(location.x,location.y - 50); } 它工作正常,但当我走出红色的对象释放如何CSN我解决这个问题 – 2011-03-21 20:35:41
请澄清你的问题,至少我不明白你想达到什么。 – 2011-03-21 19:59:02
@Erik Aigner,我只想让对象只在红色矩形中移动,换句话说,我需要限制对象的协调(x,y) – 2011-03-21 20:10:02