I'm using this code to spawn in a row of five bricks on top of one another. The first row is perfect, in position and move properly. However, the rows that spawn with the performSelector action are not being put in properly. The positions of the rows that spawn in are off halfway off the screen and instead of spawning the amount of 5 bricks, it spawns 25 the second time and the third time it spawn 125 bricks. I've used all the actions and methods in this project before without any problems can someone please tell me what's going on here.
This is the only code I have in the scene other than initWithSize and they wouldn't cause any problems.
-(void) addBricks:(CGSize)size {
for (int i = 0; i < 5; i++) {
//create brick sprite from image
SKSpriteNode *brick = [SKSpriteNode spriteNodeWithImageNamed:@"brick"];
//resize bricks
brick.size = CGSizeMake(60, 30);
//psoition bricks
int xPos = size.height/7.5 * (i+.5);
int yPos = 450;
brick.position = CGPointMake(xPos, yPos);
//add move action
SKAction *wait = [SKAction waitForDuration:3];
SKAction *move = [SKAction moveByX:0 y:-36.9 duration:1];
SKAction *sequence = [SKAction sequence:@[wait, move]];
SKAction *repeatMove = [SKAction repeatActionForever:sequence];
//add action to spawn bricks
SKAction *spawn = [SKAction performSelector:@selector(addBricks:) onTarget:(self)];
SKAction *delay = [SKAction waitForDuration:6];
SKAction *delayThenSpawn = [SKAction sequence:@[delay, spawn]];
[self runAction:delayThenSpawn];
[brick runAction:repeatMove];
[self addChild:brick];
}
}
Any help would be greatly appreciated.