我正在写一个游戏。在攻击者杀死一名士兵之后,将会显示一个丢弃的UIImageView说经验+ 1。
现在,当我杀死第一名士兵时动画显示正确,但是当杀死第二名士兵时,不显示。
动画代码,方法名称为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];
调用动画代码,
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;
有什么问题?提前谢谢!
答案 0 :(得分:1)
现在问题已解决。每次我想要动画,我都会创建一个新的UIImageView来做到这一点。不重复使用xib文件中定义的UIImageView。