Xcode, iphone - Make image animation move in specific direction [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
开发者_开发百科 Improve this questionI'm creating an animated ball which should move across the screen. I want to make it move towards the center of the screen as if it is attracted by the center. How can I do this?
You can try this code
[UIView beginAnimations:nil context:NULL]; //starting Animation
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:10];
[UIView setAnimationRrepeatAutoreverses:YES];
CGPoint position = 200.0f;
position.y = 200.0f;
position.x = 150.0f;
img.center = position;
[UIView commitAnimations];
If it is cocos2d,You can use Move method,
id move = [CCMoveTo actionWithDuration:3 position:ccp(160,240);
[sprite runAction:move];
image.center = CGPointMake(image.center.x + 10, image.center.y);
精彩评论