首先是我的touchesBegan函数,然后是存储我的对象值的结构。我有一个这些对象的数组,我试图找出当我触摸屏幕时触摸屏幕上的对象。
我不知道是否需要通过遍历所有对象来确定是否需要这样做,并弄清楚我是否正在以某种方式触摸对象,或者是否有更简单有效的方式。
这通常如何处理?
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesEnded:touches withEvent:event];
UITouch* touch = ([touches count] == 1 ? [touches anyObject] : nil);
CGRect bounds = [self bounds];
CGPoint location = [touch locationInView:self];
location.y = bounds.size.height - location.y;
float xTouched = location.x/20 - 8 + ((int)location.x % 20)/20;
float yTouched = location.y/20 - 12 + ((int)location.y % 20)/20;
}
typedef struct object_tag // Create A Structure Called Object
{
int tex; // Integer Used To Select Our Texture
float x; // X Position
float y; // Y Position
float z; // Z Position
float yi; // Y Increase Speed (Fall Speed)
float spinz; // Z Axis Spin
float spinzi; // Z Axis Spin Speed
float flap; // Flapping Triangles :)
float fi; // Flap Direction (Increase Value)
} object;