I am trying to set up an animation where a ball has a velocity, and is accelerated towards touch points. First, I successfully transcribed an app from a tutorial that worked flawlessly, from http://www.youtube.com/watch?v=buFCoj2jqDk&feature=relmfu .
But when I tried to introduce the concept of velocity, I appear to have failed at the vector math. I wanted to simply subtract two vectors from each other, but I didn’t get the syntax right for that until I went to the verbose option below.
The app gives a “Breakpoint 1.1”
Relevant code below:
@interface ViewController : UIViewController {UIImageView *spritey; CGPoint vee; CGPoint acc;}
@property (nonatomic, retain) UIImageView *spritey;
@property (assign) CGPoint vee;
@property (assign) CGPoint acc;
@end
//.m
- (void)viewDidLoad
{
[super viewDidLoad];
spritey = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"cloud2.png"]];
[spritey setFrame:CGRectMake(60,60,50,50)];
[self.view addSubview:spritey];
vee=CGPointMake(0,0);
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *myTouch=[ touches anyObject];
[UIView beginAnimations:@"moveTo" context:NULL];
[UIView setAnimationDuration: 2.25];
[UIView setAnimationBeginsFromCurrentState:YES];
CGPoint newTarget=[myTouch locationInView:self.view];
vee=CGPointMake(vee.x+(newTarget.x-spritey.center.x)/10,
vee.y+(newTarget.y-spritey.center.y)/10);
spritey.center=CGPointMake(spritey.center.x+vee.x,spritey.center.y+vee.y);
//spritey.center=[myTouch locationInView:self.view];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView commitAnimations];
Stopping at a breakpoint is a debugging tool, not an error, according to our friend here:
"Thread 1: stopped at breakpoint" error when initializing an NSURL object
Somehow I must have turned one on.
Going to View–> Navigators –> Show Breakpoint Navigator bought me to a place where I could delete it.
Code now works as intended!