如果您触摸特定物体并移动手指,则物体会跟随您的手指。当您触摸屏幕但不对象时,则没有任何反应。
这是我的代码:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [touches anyObject];
CGPoint myPoint = [myTouch locationInView:self.view];
_plaatje.center = CGPointMake(myPoint.x, myPoint.y);
}
我怎样才能做到这一点?
答案 0 :(得分:0)
假设_plaatje
为SKNode
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint mytouch = [[[event allTouches] anyObject]locationInView:self.view];
if((myTouch.x>_plaatje.center.x-(_plaatje.frame.size.width)/2)&&(myTouch.x<_plaatje.center.x+(_plaatje.frame.size.width)/2)&&(myTouch.y>_plaatje.center.y-(_plaatje.size.frame.height)/2)&&(myTouch.y<_plaatje.center.y+(_plaatje.frame.size.height)/2))
{
_plaatje.center = [mytouch locationInView:self.view];
}
}