开发者

CCMoveTo has no effect on my CCSprites

all. I have some function "tetrisl" in this function I want to move tetris sprites down:

-(void)tetrisL:(ccTime)dt {

    Tetris *s = [[Tetris node]initWithArraySize:4];
    [s createL];
    for (CCSprite *new in s.tetrisArray) {
        [self addChild:new];

        id actionMove = [CCMoveTo actionWithDuration:3 position:ccp(new.position.x,0)];
        [new runAction: actionMove];

    }
    [s release];
}

But it's don't work. I think because I try to move different sprites in same Action. How can i fix it? Thanks

Here is Tetris class

@interface Tetris : CCNode {

    NSMutableArray *tetrisArray;
    Blocks *tempBlock;

}
@property (nonatomic, retain) NSMutableArray *tetrisArray;
@property (nonatomic, retain) Blocks *tempBlock;
-(id)initWithArraySize:(int)sz;
-(void)createL;


@implementation Tetris
@synthesize tetrisArray;
@synthesize tempBlock;

-(id)initWithArraySize:(int)sz {

    if( (self=[super init] )) {
        tetrisArray = [[NSMutableArray alloc]initWithCapacity:sz];

    }
    return self;
}
-(void)createL {

    int xPos = 10;
    int yPos = 460;
    for (int i = 0; i < 4; i++) {
        tempBlock = [[Blocks node]initWithType:1];
        tempBlock.blockSprite.position = ccp(xPos,yPos);
        [tetrisArray addObject:tempBlock.blockSpri开发者_开发百科te];
        xPos = xPos + 26;
        [tempBlock release];

    }

}

-(void)dealloc {

    [tempBlock release];
    [tetrisArray release];
    [super dealloc];
}


you can't assign one action to different sprites. One action - one sprite. You can use action copy function to dublicate actions.

But in your case action creates in loop, so it must be different actions... may be problem somewhere else.


Defferent sprites cann't execute the same action at the same time, so you should copy the action, like following code:

  sprite->runAction((CCActionInterval*)aciotn->copy->autoRelease());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜