1
我在寫遊戲。在攻擊者殺死一名士兵之後,一個下降的UIImageView說經驗+1會顯示出來。UIImageView的動畫僅運行一次
現在,當我殺死第一名士兵時,動畫顯示正確,但是在第二名士兵以及後來殺死時沒有顯示。
動畫代碼,方法名稱是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;
是什麼問題?提前致謝!