title: Sprite Kit - Add random Sprite Nodes to the scene with Switch Case
body: <p>I have the following code to create random objects and add them to the scene. At the end the method is repeated after a random delay.</p>
  
  <pre><code>-(void)createObjects {
  
  // Create random start point
  float randomStartPoint = arc4random_uniform(4) * 64 + 32;
  CGPoint startPoint = CGPointMake(self.size.width + 50, randomStartPoint);
  
  // Create random object and add to scene
  switch (arc4random_uniform(2)) {
      case 0:
      {
          SKSpriteNode *crate = [SKSpriteNode spriteNodeWithImageNamed: @"crate"];
  
          crate.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:crate.frame.size];
          crate.physicsBody.dynamic = YES;
          crate.physicsBody.affectedByGravity = NO;
          crate.physicsBody.categoryBitMask = objectCategory;
          crate.physicsBody.collisionBitMask = 0;
          crate.physicsBody.contactTestBitMask = playerCategory;
  
          crate.position = startPoint;
          crate.name = @"object";
          crate.zPosition = 20;
  
          [self addChild:crate];
          break;
      }
  
      case 1:
      {
          SKSpriteNode *cactus = [SKSpriteNode spriteNodeWithImageNamed: @"cactus"];
  
          cactus.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:cactus.frame.size];
          cactus.physicsBody.dynamic = YES;
          cactus.physicsBody.affectedByGravity = NO;
          cactus.physicsBody.categoryBitMask = objectCategory;
          cactus.physicsBody.collisionBitMask = 0;
          cactus.physicsBody.contactTestBitMask = playerCategory;
  
          cactus.position = startPoint;
          cactus.name = @"object";
          cactus.zPosition = 20;
  
          [self addChild:cactus];
          break;
      }
  
      default:
          break;
  }
  
  // After adding child, call same method at random delay
  float randomNum = arc4random_uniform(4) * 0.4 + 0.25;
  [self performSelector:@selector(createObjects) withObject:nil afterDelay:randomNum];
  }
  </code></pre>
  
  <p>In reality I have many more cases and a lot of the same code is repeated, since every Sprite Node has the same settings. Is there a way to create a sprite node once, and in every case set a different image for the node, and add it to the scene?</p>