View Single Post
ad407

 
Member Since: Apr 20, 2014
Posts: 4
ad407 is on a distinguished road

ad407 is offline
I am trying to make the IF statement dependent on what the objects x and y co-ordinates are.

Here is part of my code:
Code:
- (void)oneFingerSwipeLeft:(UITapGestureRecognizer *)recognizer {
    // Code to handle swipe left
    
    if (Ball.origin.x = 12, Ball.origin.y = 20){
    
        //If the x co-ordinate of the ball is at 12 and the y co-ordinate is at 20
        
    CGRect frame = Ball.frame;
    frame.origin.x = 74;
    frame.origin.y = 209;
    
    Ball.frame = frame;
        
    Ball.image = [UIImage imageNamed:@"Ball1.png"];
        
    // Then change the position of the ball to the x co-ordinate = 74 and the y co-ordinate = 209
    }

    if (Ball.origin.x = 74, Ball.origin.y = 209){
        
        //If the x co-ordinate of the ball is at 74 and the y co-ordinate is at 209

    CGRect frame = Ball.frame;
    frame.origin.x = 25;
    frame.origin.y = 54;

    Ball.frame = frame;

    Ball.image = [UIImage imageNamed:@"Ball2.png"];
        
        //Then change the position of the ball to the x co-ordinate = 25 and the y co-ordinate = 54
}
}
The part I'm struggling with is making the condition of the IF Statement dependent on the x and y co-ordinates of the "Ball". So how would I say:

IF the x co-ordinate is 5 and the Y co-ordinate is 7, run this piece of code:

....

Or am I going the complete wrong way about this?

Thanks!

Last edited by Raz0rEdge; 04-21-2014 at 04:17 PM. Reason: CODE'ify segment
QUOTE Thanks