How to make this building blocks code more flexible / efficient? <p>The code below stacks bricks on top of each other. When <code>TouchesBegin</code> is called a new brick is added. </p> <p>I am new to coding. I want the code to be more flexible, so different kind of shapes of bricks can be added too.</p> <p>Thanks for helping.</p> <p><strong>CODE</strong></p> <pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called when a touch begins */ if (integer == 0) { [_previousBrick removeAllActions]; [self spawnNextBrick]; } if (integer == 1) { [self spawnPrevBrick]; } } -(void)spawnPrevBrick { _previousBrick = [SKSpriteNode spriteNodeWithImageNamed:@"TestBridgePiece"]; _previousBrick.anchorPoint = CGPointMake(0.5, 0.0); _previousBrick.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_previousBrick.frame.size]; _previousBrick.position = CGPointMake(0.0, _nextBrick.position.y + _previousBrick.size.height); _previousBrick.physicsBody.categoryBitMask = bridgeCategory; _previousBrick.physicsBody.contactTestBitMask = leftEdgeCategory | rightEdgeCategory | newBrickNotificator; _previousBrick.physicsBody.collisionBitMask = bridgeCategory; _isPreviousBrick = YES; [_previousBrickLayer addChild:_previousBrick]; } -(void)spawnNextBrick { _nextBrick = [SKSpriteNode spriteNodeWithImageNamed:@"TestBridgePiece"]; _nextBrick.anchorPoint = CGPointMake(0.5, 0.0); _nextBrick.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_nextBrick.frame.size]; _nextBrick.position = CGPointMake(self.size.width, _previousBrick.position.y + _nextBrick.size.height); _nextBrick.physicsBody.contactTestBitMask = leftEdgeCategory | rightEdgeCategory | newBrickNotificator; _nextBrick.physicsBody.collisionBitMask = bridgeCategory; _isPreviousBrick = NO; [_previousBrickLayer addChild:_nextBrick]; } -(void)update:(CFTimeInterval)currentTime { if (_isPreviousBrick == NO) { integer = 1; } if (_isPreviousBrick == YES) { integer = 0; } NSLog(@"integer = %i", integer); } </code></pre>