I am writing a game. After attacker kills a soldier, a dropping UIImageView saying experience+1 will show.
Now, the animation shows correctly when I kills 1st soldier, but not show when killing 2nd soldier and later.
animation codes, method name is showGainXPAnimationAfterKillSoldier.
imgGainXPAfterKillSoldier.hidden = FALSE;
[imgGainXPAfterKillSoldier.layer removeAllAnimations];
imgGainXPAfterKillSoldier.frame = CGRectMake(140, 220, 53, 19);
// a loop to show animation.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:1.5];
//imgGainXPAfterKillSoldier.frame = CGRectMake(100, 200, 53, 19);
CGAffineTransform transform = CGAffineTransformMakeTranslation(-112, 215);
imgGainXPAfterKillSoldier.transform = transform;
//imgGainXPAfterKillSoldier.alpha = 0.0f;
[UIView commitAnimations];
call animation codes,
if (killedSoldierCount>0) {
// add imgview to show gained XP.
if (imgGainXPAfterKillSoldier) {
MWLog(@"remove it!");
[imgGainXPAfterKillSoldier.layer removeAllAnimations];
[imgGainXPAfterKillSoldier removeFromSuperview];
}
imgGainXPAfterKillSoldier.frame = CGRectMake(140, 220, 53, 19);
imgGainXPAfterKillSoldier.hidden = TRUE;
//imgGainXPAfterKillSoldier.alpha = 1.0f;
[self.view addSubview:imgGainXPAfterKillSoldier];
switch (killedSoldierCount) {
case 1:
// show add experience animation after kill soldier.
MWLog(@"kill a soldier, show XP+1 animation.");
[self showGainXPAnimationAfterKillSoldier:1];
break;
what is the problem? Thanks in advance!
now the problem is fixed. every time I want to animate, I create a new UIImageView to do that. without using the UIImageView defined in xib file repeatly.