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

  • Home
  • SEARCH
  • 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 8933157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:28:24+00:00 2026-06-15T09:28:24+00:00

I’m working on an app where two views meet somewhere on the screen. When

  • 0

I’m working on an app where two views meet somewhere on the screen. When they meet, a collision detector fires off this method. It’s supposed to identify the appropriate base and then send both views to it. It does exactly that, but it happens instantly instead of over a period of 4 seconds. What am I missing? RADIUS is defined above this code. Does it have anything to do with arrow not being a UIView? The spriteView class is a subclass of UIView.

-(void)sendToBase:(spriteView *)arrow
{
   int teamNumber = arrow.teamNumber;
   // Find the location of the base.
   for (UIView *scaledView in self.view.subviews) {
      if (scaledView.tag == 100) {
         for (UIView *base in scaledView.subviews) {
            if (base.tag >= 1000) {
               if (teamNumber + 1000 == base.tag) {
                  // We found the right base.
                  CGPoint newCenter;
                  newCenter.x = base.center.x + arc4random() % (int) floor(RADIUS) - RADIUS/2.0;
                  newCenter.y = base.center.y + arc4random() % (int) floor(RADIUS) - RADIUS/2.0;
                  [UIView animateWithDuration:4.0 delay:0.0 options:UIViewAnimationCurveLinear animations:^{
                     [arrow setCenter:newCenter];
                  } completion:^(BOOL finished) {
                     // After walking back to base, remove and create new objects
                     [arrow removeFromSuperview];
                     [self addArrow:scaledView toTeam:teamNumber];
                  }];
               }
            }
         }
      }
   }
}

On the off-chance that the class type mismatch was the problem, I modified the code thusly, with the same results.

-(void)sendToBase:(spriteView *)arrow
{
   UIView *uiSpriteView = (UIView *)arrow;
   int teamNumber = arrow.teamNumber;
   // Find the location of the base.
   for (UIView *scaledView in self.view.subviews) {
      if (scaledView.tag == 100) {
         for (UIView *base in scaledView.subviews) {
            if (base.tag >= 1000) {
               if (teamNumber + 1000 == base.tag) {
                  // We found the right base.
                  CGPoint newCenter;
                  newCenter.x = base.center.x + arc4random() % (int) floor(RADIUS) - RADIUS/2.0;
                  newCenter.y = base.center.y + arc4random() % (int) floor(RADIUS) - RADIUS/2.0;
                  [UIView animateWithDuration:4.0 delay:0.0 options:UIViewAnimationCurveLinear animations:^{
                     [uiSpriteView setCenter:newCenter];
                  } completion:^(BOOL finished) {
                     // After walking back to base, remove and create new objects
                     [arrow removeFromSuperview];
                     [self addArrow:scaledView toTeam:teamNumber];
                  }];
               }
            }
         }
      }
   }
}
  • 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-15T09:28:26+00:00Added an answer on June 15, 2026 at 9:28 am

    I solved the problem (using setCenter). There are two animations going on.

    The first animation occurs before the collision.
    The second animation occurs as a result of the collision.

    The code that detects the collision (and thus spawns the second animation) was in the animation block instead of the completion block. When I moved the code to the completion block, the second animation worked. Well, almost. One of the two arrows were animated properly. I can probably ferret out the other issue now that one of them is working.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.