Xcode, iphone - 使图像动画朝特定方向移动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5679952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:50:25 来源:igfitidea点击:
Xcode, iphone - Make image animation move in specific direction
提问by arvin Arabi
I'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?
我正在创建一个应该在屏幕上移动的动画球。我想让它向屏幕中心移动,就好像它被中心吸引一样。我怎样才能做到这一点?
采纳答案by Anish
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,
如果是cocos2d,可以使用Move方法,
id move = [CCMoveTo actionWithDuration:3 position:ccp(160,240);
[sprite runAction:move];
回答by MAXHASADHD
image.center = CGPointMake(image.center.x + 10, image.center.y);