0
我有一個精靈數組,並在每個元素上運行一個動作。我遇到的問題是最後一個精靈是唯一一個移動的。在多個精靈上運行CCAction
如果我添加3列,並通過每個迭代,並使用以下
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:moveSequence];
[[row1 objectAtIndex:i] runAction:repeat];
它只能移動最後繪製的精靈。
如何對Array中的每個元素執行一個操作?
我需要物體同時移動。所以所有精靈都應該同時運行這個動作。這是可能的cocos2d的
編輯* * ** * ** * ** * ** * ** *
- (void) moveAliens
{
id left = [CCMoveBy actionWithDuration:10 position:ccp(-35, 0)];
id right = [CCMoveBy actionWithDuration:10 position:ccp(35, 0)];
id moveSequence = [CCSequence actions:left, [CCDelayTime actionWithDuration:20], right, [CCDelayTime actionWithDuration:20], nil];
id repeatMoveSequence = [CCRepeatForever actionWithAction:moveSequence];
for (int i = 0; i < [row1 count]; i++)
{
NSLog(@"i is %d", i);
//CCRepeatForever *repeat = [CCRepeatForever actionWithAction:moveSequence];
[[row1 objectAtIndex:i] runAction:repeatMoveSequence];
}
}
感謝
你可以添加你的循環代碼,也許你如何設置你的數組?另外,任何你不通過* sprite而不是通過objectatindex循環你的數組的原因? – Sup3rpanda
我加了我的代碼,謝謝。請看一下。 – user773578