2010-03-16 6 views
1

Je crée un jeu de cartes sur iphone.Animer plusieurs UIView dans un cycle

Mon problème est que je veux animer les cartes au début du jeu en faisant animer les cartes d'un point à un autre point dans un paquet.

Je déplace mes cartes qui sont UIView, dans un cycle. c'est ce que je fais

Avec ce code, toutes les cartes se déplacent ensemble, je dois déplacer les cartes séparément l'un après l'autre

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]; 

} 

dans la vue de la carte il y a ces méthodes

-(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]; 

} 

Répondre

0

Je pense que la chose la plus facile serait d'utiliser le compteur i pour calculer un léger retard en fonction de l'index de la carte - puis en passant cela à la méthode positionCard.

Alors:

[aCardView positionCardWithDelay:i/10]; 

Et:

-(void)positionCardWithDelay:(NSNumber)delay 
{ 
    // Call _position card after a slight delay 
    [self performSelector:@selector(_positionCard) withObject:nil afterDelay:delay]; 
} 
+0

Merci, je essayé, courir, mais le flux de mouvement est non régulier, une vue toghether déplacer. merci encore – Giovanni

+0

OK, Résolu, en utilisant i/40.4 comme délai. Merci beaucoup – Giovanni