Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:05:54+00:00 2026-06-10T18:05:54+00:00

I am trying to create a for loop within a method that will animate

  • 0

I am trying to create a for loop within a method that will animate a computer controlled enemy player a predetermined distance 6 times whenever it is the enemy’s turn. Currently with the below code the enemy moves toward the player’s character, but the loop runs it far too quickly, so instead of the enemy animating each time it moves, it only animates the final movement.

Essentially what I am attempting to do is at the end of the loop cause a short (.75 second) delay to slow the looping down to an acceptable amount. I have searched high and low on the internet for this information and I’m surprised I can’t find the answer. It seems like it would be incredibly simple. Any help would be greatly appreciated!

for (int i=0; i<6; i++) {
    // Enemy NE
    if (enemyZombie.center.x < orcIdle.center.x && enemyZombie.center.y > orcIdle.center.y){

        [UIView animateWithDuration:.75 animations:^{ enemyZombie.center = CGPointMake(enemyZombie.center.x + 42.5, enemyZombie.center.y - 30); }];
    }
    // Enemy NW
    if (enemyZombie.center.x > orcIdle.center.x && enemyZombie.center.y > orcIdle.center.y){

        [UIView animateWithDuration:.75 animations:^{ enemyZombie.center = CGPointMake(enemyZombie.center.x - 42.5, enemyZombie.center.y - 30); }];
    }
    // Enemy SE
    if (enemyZombie.center.x < orcIdle.center.x && enemyZombie.center.y < orcIdle.center.y){

        [UIView animateWithDuration:.75 animations:^{ enemyZombie.center = CGPointMake(enemyZombie.center.x + 42.5, enemyZombie.center.y + 30); }];
    }
    // Enemy SW
    if (enemyZombie.center.x > orcIdle.center.x && enemyZombie.center.y < orcIdle.center.y){

        [UIView animateWithDuration:.75 animations:^{ enemyZombie.center = CGPointMake(enemyZombie.center.x - 42.5, enemyZombie.center.y + 30); }];
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:05:56+00:00Added an answer on June 10, 2026 at 6:05 pm

    You can use the completion block in UIView’s selector animateWithDuration:animations:completion: to recursively perform the next step in your loop like this:

    -(void)moveEnemyZombieWithSteps:(int)steps
    {
        // check for end of loop
        if (steps == 0) return;
    
        // Enemy NE
        if (enemyZombie.center.x < orcIdle.center.x && enemyZombie.center.y > orcIdle.center.y)
        {
    
            [UIView animateWithDuration:.75
                             animations:^{ enemyZombie.center = CGPointMake(enemyZombie.center.x + 42.5, enemyZombie.center.y - 30);}
                             completion:^(BOOL finished){[self moveEnemyZombieWithSteps:steps - 1];}];
        }
        // Enemy NW
        ...
    }
    
    //start moving
    moveEnemyZombieWithSteps(6);
    

    Haven’t tested the code, but you’ll get the idea 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a function that will loop through an array of various
Trying to create a method that will count the amount of matching elements between
I'm trying to create a loop that creates a series of objects that contains
I'm trying to create a for loop with NSDates, so that the loop would
I am trying to use R within a script that will act as a
I’m trying to create a routine that replaces a variable number of values within
I'm trying to create a list using a loop within a loop. I have
I'm trying to create a game that involves the computer typing to you. I'm
I'm trying to create a loop than continues to take input until the input
I am trying to create a loop function based on the time. After the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.