开发者

animationArray only playing last image

I currently have this method buttonHit that calls playAnimationToNumber which accepts an int, which is then in turn used to run through a loop playing an array of images for each iteration, however it only seems to be playing the last array.. can you see why? because I am slightly lost and would appreciate the help.

//attached to button and it calls animation method.
- (void)buttonHit:(id)sender{
    [self playAnimationToNumber:5];
}



- (void)playAnimationToNumber:(int)number{

    for (int counter=1; counter<=number; counter++) {

        NSString *imageNameForFirstNumber = [NSString stringWithFormat:@"Flap%i.png", counter];
        NSArray *imagesForAnimation = [NSArray arrayWithObjects:开发者_JAVA百科[UIImage imageNamed:@"FlapMoving1.png"], [UIImage imageNamed:@"FlapMoving2.png"], [UIImage imageNamed:imageNameForFirstNumber], nil];


        animationArray.animationImages = [[NSArray alloc] initWithArray:imagesForAnimation];        

        animationArray.animationDuration = 0.5;
        animationArray.animationRepeatCount = 1;
        [animationArray startAnimating];
        [self.view addSubview:animationArray];



    }


    [animationArray release];
}

WORKING CODE ' - (void)playAnimationToNumber:(int)number{

NSMutableArray *imagesForAnimation = [[NSMutableArray alloc] initWithCapacity:0];


for (int counter=1; counter<=number; counter++) {

    NSString *imageNameForFirstNumber = [NSString stringWithFormat:@"Flap%i.png", counter];
    [imagesForAnimation addObject:[UIImage imageNamed:@"FlapMoving1.png"]];
    [imagesForAnimation addObject:[UIImage imageNamed:@"FlapMoving2.png"]];
    [imagesForAnimation addObject:[UIImage imageNamed:imageNameForFirstNumber]];
}
animationArray.animationImages = [NSArray arrayWithArray:imagesForAnimation];        

animationArray.animationDuration = 5.9;
animationArray.animationRepeatCount = 1;
[animationArray startAnimating];
[self.view addSubview:animationArray];
[imagesForAnimation release];   

}'


Here you go try this code.

   - (void)playAnimationToNumber:(int)number{

    NSMutableArray *imagesForAnimation = [[[NSMutable alloc] initWithCapacity:0] autoRelease];
    [imagesForAnimation addObject:[UIImage imageNamed:@"FlapMoving1.png"]];
    [imagesForAnimation addObject:[UIImage imageNamed:@"FlapMoving2.png"]];

        for (int counter=1; counter<=number; counter++) {

            NSString *imageNameForFirstNumber = [NSString stringWithFormat:@"Flap%i.png", counter];
            [imagesForAnimation addObject:[UIImage imageNamed:imageNameForFirstNumber]];
    }
            animationArray.animationImages = [NSArray arrayWithArray:imagesForAnimation];        

            animationArray.animationDuration = 0.5;
            animationArray.animationRepeatCount = 1;
            [animationArray startAnimating];
            [self.view addSubview:animationArray];



        }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜