Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
iOS Development
Coordinate Dependent If Statements
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="ad407" data-source="post: 1579220" data-attributes="member: 324813"><p>I am trying to make the IF statement dependent on what the objects x and y co-ordinates are.</p><p></p><p>Here is part of my code:</p><p>[CODE]</p><p>- (void)oneFingerSwipeLeft:(UITapGestureRecognizer *)recognizer {</p><p> // Code to handle swipe left</p><p> </p><p> if (Ball.origin.x = 12, Ball.origin.y = 20){</p><p> </p><p> //If the x co-ordinate of the ball is at 12 and the y co-ordinate is at 20</p><p> </p><p> CGRect frame = Ball.frame;</p><p> frame.origin.x = 74;</p><p> frame.origin.y = 209;</p><p> </p><p> Ball.frame = frame;</p><p> </p><p> Ball.image = [UIImage imageNamed:@"Ball1.png"];</p><p> </p><p> // Then change the position of the ball to the x co-ordinate = 74 and the y co-ordinate = 209</p><p> }</p><p></p><p> if (Ball.origin.x = 74, Ball.origin.y = 209){</p><p> </p><p> //If the x co-ordinate of the ball is at 74 and the y co-ordinate is at 209</p><p></p><p> CGRect frame = Ball.frame;</p><p> frame.origin.x = 25;</p><p> frame.origin.y = 54;</p><p></p><p> Ball.frame = frame;</p><p></p><p> Ball.image = [UIImage imageNamed:@"Ball2.png"];</p><p> </p><p> //Then change the position of the ball to the x co-ordinate = 25 and the y co-ordinate = 54</p><p>}</p><p>}</p><p>[/CODE]</p><p>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: </p><p></p><p>IF the x co-ordinate is 5 and the Y co-ordinate is 7, run this piece of code:</p><p></p><p>....</p><p></p><p>Or am I going the complete wrong way about this?</p><p></p><p>Thanks!</p></blockquote><p></p>
[QUOTE="ad407, post: 1579220, member: 324813"] 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 } } [/CODE] 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! [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
iOS Development
Coordinate Dependent If Statements
Top