2011-03-02 67 views
0

我使用的是cocos2d,我有一个for循环来创建一组精灵,并且我正在forloop中的每个精灵上运行一个动作,但是当我运行模拟器时,我看不到动作.. some1请帮我Cocos2d CCSpirte runAction问题

  CCAction * action = [CCSequence actions:[CCFadeIn actionWithDuration:2],nil]; 
      for(NSInteger lp = 0;lp<49;lp++) 

    { 
     float sizer = [[numberOfElement objectAtIndex:lp]floatValue]; 




     CCSprite *_bar = [CCSprite spriteWithFile:colorOfBar rect:  (CGRectMake(10,20,5,sizer*30))]; 
     _bar.position = ccp(5+9.5*lp,((sizer*30)/2)+25); 

     [self addChild:_bar z:1]; 

     [_bar runAction:action]; 


    } 
+0

你能看到屏幕上的精灵吗? – xuanweng 2011-03-02 09:17:07

回答

1

您需要为每个节点创建Action实例。

for(NSInteger lp = 0;lp<49;lp++) 
{ 
    float sizer = [[numberOfElement objectAtIndex:lp]floatValue]; 

    CCSprite *_bar = [CCSprite spriteWithFile:colorOfBar rect:(CGRectMake(10,20,5,sizer*30))]; 
    _bar.position = ccp(5+9.5*lp,((sizer*30)/2)+25); 

    [self addChild:_bar z:1]; 

    CCAction * action = [CCSequence actions:[CCFadeIn actionWithDuration:2],nil]; 
    [_bar runAction:action]; 
}