views:

123

answers:

0

First is my touchesBegan function and then the struct that stores the values for my object. I have an array of these objects and I'm trying to figure out when I touch the screen if I'm touching an object on the screen.

I don't know if I need to do this by iterating through all my objects and figure out if I'm touching an object that way or maybe there is an easier more efficient way.

How is this usually handled?

 -(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;