views:

141

answers:

1

Hi all, i'm creating a card game on iphone.

My problem is that i want to animate the cards at the beginning of the game making the cards animate from a point to another point in a deck.

I move my cards that are UIView, in afor cicle. this is what i do

With this code, alla tha cards move together, i need to move the cards separately one after another

    CGPoint point;

// Create the deck of playing cards
for (int i = 0; i < 28; i++) {  
    CardView *aCardView = [self.mazzo objectAtIndex:i];

    point.x = -100;
    point.y = 200;
    aCardView.center = point;   

    aCardView.zPosition = i;

    [self.viewGioco addSubview:aCardView];

    [aCardView release];

            //Here i call the method to position the card
    [aCardView positionCard];

}

in the card view there are this methods

-(void)positionCard{
    [self performSelector:@selector(_positionCard) withObject:nil afterDelay:0.0];
}
-(void)_positionCard{

[UIView beginAnimations:@"posizionacarta" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.3f];

CGPoint point;

point.x = 280 + ((arc4random() % 2) - 1);
point.y = 240 + ((arc4random() % 2) - 1);

self.center = point;

[UIView commitAnimations];

[self setNeedsLayout];  

}
A: 

I think the easiest thing would be to use the counter i to calculate a slight delay based on the index of the card - and then passing this to the the positionCard method.

So:

[aCardView positionCardWithDelay:i/10];

And:

-(void)positionCardWithDelay:(NSNumber)delay
{
    // Call _position card after a slight delay
    [self performSelector:@selector(_positionCard) withObject:nil afterDelay:delay];
}
Paulo Fierro
Thanks,I tried, it run, but the movement flow is non regular, some view move toghether.thanks again
Giovanni
OK, Solved, using i/40.4 as delay.Thanks a lot
Giovanni