Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a method that is moving a UIImageView called shootImg across the screen:

-(IBAction)shoot{
if (appDelegate.shootInt > 0) {
    if (direction == 1) {
            shootImg.center = CGPointMake(shootImg.center.x+1, shootImg.center.y);
            appDelegate.shootInt = appDelegate.shootInt - 1;
            shootLabel.text = [NSString stringWithFormat:@"%d", appDelegate.shootInt];
                }

This does seem to work. But it only moves shootImage 1 pixel. What I want to do is make it repeatedly move 1 pixel. I tried a while loop but that didn't seem to work. I'm not using cocos2d or anything like that and if you need to see more code just ask.

Thanks :)

share|improve this question
    
It would be better if you showed us the context of where you're using the shoot method. –  Byte56 Mar 30 '12 at 14:33
    
Well it's just a UIButton. What do you mean by context? –  Will Mar 30 '12 at 14:58
    
I see now. The function above is just a response to a button press? –  Byte56 Mar 30 '12 at 15:20
    
Yeah, and shootimg is a UIImageView –  Will Mar 30 '12 at 15:33

2 Answers 2

up vote 2 down vote accepted
[UIView beginAnimations:nil context:nil];
shootImg.center = CGPointMake(shootImg.center.x+appDelegate.shootInt, shootImg.center.y);
[UIView commitAnimations];

you can use this to animate the motion of ur image over 0.25 secs. But if you want to change the duration or any other animation properties then refer the doc.

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

share|improve this answer

How about making your own method in moving your object.. and inside your if statement:

a loop the calls this method: [self performSelector:@selector(methodname) withObject:nil afterDelay:1]; //this calls the method that moves your object every after 1 second.. as many times as you want..

share|improve this answer
    
Your post is incomprehensible. I suggest you clean up your language and format your post a little, including the code. –  Jonathan Hobbs Sep 23 '12 at 23:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.