2013-11-20 41 views
0

CCLabelTTF的動畫是通過按下按鈕觸發的。但是如果我將這個動畫用於某些CCLabelTTF,則該動畫僅適用於後者。哪裏不對?幾個CClabel的動畫TTF

 id scaleDown = [CCScaleTo actionWithDuration:.4 scale:0.5]; 
     id scaleUp = [CCScaleTo actionWithDuration:.2 scale:1.5]; 
     id scaleBack = [CCScaleTo actionWithDuration:.2 scale:1.0]; 
     id combination = [CCSequence actions:scaleDown, scaleUp, scaleBack, nil]; 
     id repeat = [CCRepeat actionWithAction:combination times:3]; 
     [Var1Podpis,Var2Podpis,Var3Podpis runAction:repeat]; 

回答

3

行爲不能同時在多個目標上......它們包含關於特定目標的狀態。您應該將所有代碼都放在方法中重複創建,並且每個目標都運行一次。

-(CCAction*) pulseAction { 
    id scaleDown = [CCScaleTo actionWithDuration:.4 scale:0.5]; 
    id scaleUp = [CCScaleTo actionWithDuration:.2 scale:1.5]; 
    id scaleBack = [CCScaleTo actionWithDuration:.2 scale:1.0]; 
    id combination = [CCSequence actions:scaleDown, scaleUp, scaleBack, nil]; 
    id repeat = [CCRepeat actionWithAction:combination times:3]; 
    return repeat; 
} 

and then 

[Var1Podpis runAction:[self pulseAction]]; 
[Var2Podpis runAction:[self pulseAction]]; 
[Var3Podpis runAction:[self pulseAction]]; 

或類似的東西。沒有從內存中測試。

+0

我修復了一些缺失的括號,給你的方法一個更有用的名字! :P –

+0

與一個好的IDE一起工作是一個b ...它爲我做了幾乎所有的包圍,我傾向於關注它們。至於有用的,最後名言「一個人的對象是另一個人的肚子大笑」:) – YvesLeBorg

+0

@JamesWebster ... ps。愛你的大奶:) – YvesLeBorg

0

您可以複製該動作並將其運行在三個不同的目標上。

id scaleDown = [CCScaleTo actionWithDuration:.4 scale:0.5]; 
id scaleUp = [CCScaleTo actionWithDuration:.2 scale:1.5]; 
id scaleBack = [CCScaleTo actionWithDuration:.2 scale:1.0]; 
id combination = [CCSequence actions:scaleDown, scaleUp, scaleBack, nil]; 
id repeat = [CCRepeat actionWithAction:combination times:3]; 

[var1Podpis runAction:[repeat copy]]; 
[var2Podpis runAction:[repeat copy]]; 
[var3Podpis runAction:[repeat copy]]; 

注:這是慣例給instanceVariablesTitleCaseNames,即開始以小寫字符。

+0

是的,只是另一種方式皮膚同一只貓。然而,我發現我最終必須從我的控制器中的不同位置執行這些「標準動畫序列」,即本地ivar並不處處存在,因此消息傳遞給方法的額外「負載」。 – YvesLeBorg

0
-(void) pulseActionForItem:(CCNode*) item { 
     id scaleDown = [CCScaleTo actionWithDuration:.4 scale:0.5]; 
     id scaleUp = [CCScaleTo actionWithDuration:.2 scale:1.5]; 
     id scaleBack = [CCScaleTo actionWithDuration:.2 scale:1.0]; 
     id combination = [CCSequence actions:scaleDown, scaleUp, scaleBack, nil]; 
     id repeat = [CCRepeat actionWithAction:combination times:3]; 
     [item runAction:repeat]; 
    } 

[self pulseActionForItem:Var1Podpis]; ....