How to move an object from one place to another using animation in iphone applications

I'm new to developing Apple ios. I want to know what types of frameworks and libraries are used to develop game applications. I just want to know how to move objects from one place to another in the iphone application horizontally. Should an object move horizontally when I click this object? How to perform this movement of an object when the object is used by the user? Please help me with this. Please show me some examples to practice them. Please help me with this?

+1
source share
2 answers

it is very simple - just write this method in the viewController.m file. Here the button moves to where you touch the UIView.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:self.view]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; //you can change the setAnimationDuration value, it is in seconds. CGRect rect = CGRectMake(pt.x, pt.y, button.frame.size.height, button.frame.size.width); [btn setFrame:rect]; [UIView commitAnimations]; } 

Now listen - if you want to move it horizontally, then fix the y coordinate and rect will be ...

  CGRect rect = CGRectMake(pt.x, button.frame.origin.y, button.frame.size.height, button.frame.size.width); 

and if you want to move it vertically, set the x coordinate - and rect will be

  CGRect rect = CGRectMake( button.frame.origin.x, pt.y, button.frame.size.height, button.frame.size.width); 

Thanks!

+3
source

I assume that you are talking about 2D games, since you only mention moving objects on the screen. There are, of course, real game engines that are used for heavy and complex games, but from your description you do not need to sound the way you need. I also assume that you are not so far away. You can start with two kinds of animations that are native to iOS and see if there is enough for your purpose. If my above assumptions are current, you can see the links below. Otherwise, you may need to study anti-aliasing, such as Cocos2d (which I just heard about, never used).


You first need something like UITapGestureRecognizer to find out when your object was involved (which I assume is some kind of UIView). This will trigger the part that moves the animation.

Depending on how complex the animations you want to make, you should look into UIView or Core Animation. UIView-animation can only animate the main properties of the view (one of them is the center), so if you want to change the position of your views, you will be enough.

I suggest you familiarize yourself with the documentation: the most important sections for this are Animations in the iOS Programming Guide . If you want to make more advanced animations that are not possible with UIView, you should take a look at the Core Animation Programming Guide .

0
source

All Articles