オブジェクトをタッチで動かす
// タッチパネル操作
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
lastPoint = [[touches anyObject] locationInView:self.superview];
}
-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
// タッチした座標を取得
CGPoint p=[[touches anyObject] locationInView:self.superview];
// X座標の移動量を算出。直前のラストポイントと今タッチした座標の差をみている。
for (int i=0; i<N; i++) {
if ( *1 {
d[i].vx=p.x-lastPoint.x;
d[i].vy=p.y-lastPoint.y;
}
}
lastPoint = p;
}
*1:d[i].x+20)-p.x)*((d[i].x+20)-p.x)+((d[i].y+20)-p.y)*((d[i].y+20)-p.y) < (20+20)*(20+20