0
votes

Ok I'm fairly new to coding with sprite kit so I don't know too much. I'm trying to make 5 bricks spawn above the scene and then slide down into the scene every 5 seconds. I thought this code would work but it does absolutely nothing to my scene.

I have another method that has bricks already loaded into the scene and that works so I don't think that would affect this much but not really sure.

-(void) spawnMoreBricks:(CGSize)size {
    for (int i = 0; i < 5; i++) {
        SKSpriteNode *brick = [SKSpriteNode spriteNodeWithImageNamed:@"brick"];
        //resize bricks
        brick.size = CGSizeMake(60, 30);
        //position it
        brick.position = CGPointMake(self.size.width/2, self.size.height);

        SKAction *wait = [SKAction waitForDuration:5];
        SKAction *spawn = [SKAction scaleTo:1 duration:0];
        SKAction *move = [SKAction moveByX:0 y:-80 duration:3];
        SKAction *spawnSequence = [SKAction sequence:@[wait, spawn, move]];

        [self runAction:spawnSequence];



    }
}
1
In my debug area it says that "animating the position of a SKScene has no effect" - Nicholas Whitley
Please don't use the code snippet button for code, it is only for JS/HTML code. - LearnCocos2D

1 Answers

0
votes
    SKAction *wait = [SKAction waitForDuration:5];
    SKAction *spawn = [SKAction runBlock:^{[self addChild: brick];
              SKAction *move = [SKAction moveByX:0 y:-80 duration:3];
              [brick runAction: move];
               }];

    SKAction *spawnSequence = [SKAction sequence:@[wait, spawn]];

    [self runAction:spawnSequence];

Here is a modified set of actions to use. The problem was that you were running all the actions on the scene itself. The code provided runs a sequence on the scene that waits 5 seconds (acting as the delay), and then runs a spawn action. runBlock allows us to add the brick to the scene, create the move action, and apply that action to the brick (not the scene)