Note that there are some explanatory texts on larger screens.

plurals
  1. POUIImageView positioning problems?
    primarykey
    data
    text
    <p>i wrote the following code:</p> <pre><code>-(void)viewDidLoad{ JumpVelocity = 10; aStandRightArray = [[NSArray alloc] initWithObjects:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aStandR1" ofType:@"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aStandR2" ofType:@"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aStandR3" ofType:@"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aStandR2" ofType:@"png"]], nil]; aJumpRightArray = [[NSArray alloc] initWithObjects:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aJumpR" ofType:@"png"]], nil]; aStandRight = [[UIImageView alloc] initWithFrame:CGRectMake(0, 242, 55, 65)]; aStandRight.animationImages = aStandRightArray; aStandRight.animationDuration = 0.5; [self.view addSubview:aStandRight]; aJumpRight = [[UIImageView alloc] initWithFrame:CGRectMake(0, 234, 69, 65)]; aJumpRight.animationImages = aJumpRightArray; [self.view addSubview:aJumpRight];} -(IBAction)buttonJumpRight:(id)sender{ [aStandRight stopAnimating]; [aStandRight removeFromSuperview]; [aJumpRight startAnimating]; jumpTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(playerJumpRight) userInfo:nil repeats:YES];} -(void)playerJumpRight{ [aJumpRight removeFromSuperview]; aJumpRight.center = CGPointMake(aJumpRight.center.x + JumpVelocity, 234); [self.view addSubview:aJumpRight]; if(aJumpRight.center.x &gt;= 84.0) { [jumpTimer invalidate]; jumpTimer = nil; [aJumpRight stopAnimating]; aStandRight.center = CGPointMake(84, 242); [aStandRight startAnimating]; [self.view addSubview:aStandRight]; } </code></pre> <p>}</p> <p>basically what i am trying to do here is load up a standing animation, then when the user presses the buttonJumpRight button i stop then unload the standing animation. after that i load up the jump animation and begin to move it across the screen with the playerJumpRight function.</p> <p>everything seems to work fine with two exception:</p> <ol> <li><p>the jump animation moves like expected along the x axis but for some reason does not keep its original y position which in the code above is "234".</p></li> <li><p>when the jump animation x position meets the requirements for the if statement everything works like expected newly created position for the standing animation is way off of the desire position of (84, 242).</p></li> </ol> <p>i been searching for quite some time, trying out many different possible solutions but fail at every try. please excused my newbieism as i just start coding for ios/objective c.</p> <p>i greatly appreciate any help you can offer. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload