我正在尝试设置一个动画,其中一个球有一个速度,并被加速到接触点。首先,我从http://www.youtube.com/watch?v=buFCoj2jqDk&feature=relmfu的教程中成功转录了一个应用程序。
但是当我试图引入速度的概念时,我似乎在矢量数学上失败了。我想简单地把两个向量相减,但直到我进入下面的详细选项,我才得到正确的语法。
该应用程序提供了“断点 1.1”
相关代码如下:
@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];