Calculating the x coordinate for the position
of each node is pretty straightforward:
- x starts at 212
- Subsequent nodes are 200px to the right of the previous node
- Every 5th node is 424px (instead of 200px) to the right of the previous node
The code for that looks like this:
- (SKSpriteNode *)createBottomRack
{
self.rack = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:CGSizeMake(10240.0, 200)];
self.rack.position = CGPointMake(0.0,150.0);
self.rack.zPosition = 0;
self.rack.name = @"bottomRack";
float x = 212.0, y = 0.0;
for (NSUInteger i = 0; i < 20; i++) {
SKSpriteNode *dash = [SKSpriteNode spriteNodeWithImageNamed:@"dashedCard"];
dash.position = CGPointMake(x, y);
[self.rack addChild:dash];
// Calculate the next x coordinate
x += (i % 4 == 3) ? 424.0 : 200;
}
return self.rack;
}