title: Can I draw all objects of the same type at the same time?
body: <p>I am creating a 2d platformer and have created several objects in different classes.</p>
  
  <p>The code below shows how I currently create objects and draw them to the window.</p>
  
  <p>Is there a way I can draw all of the objects in a class (for example all of the collectible objects), without having to draw each individual object as seen below?</p>
  
  <pre><code>/*!
  \file game.cpp
  */
  #include "game.h"
  
  //TODO:
  //Collectibles - delete on contact
  //Enemies - move away on contact (maybe delete on contact?)
  //HUD -lives, minmap and score system
  //Win condition
  //Lose Condition
  //Build level
  
  Game::Game()
  {
      // Load textures.
      m_texture.loadFromFile("./assets/textures/sky.png");
      m_floor.loadFromFile("./assets/textures/floor.jpg");
      m_collect.loadFromFile("./assets/textures/diamond.png");
      m_bed.loadFromFile("./assets/textures/bed.png");
      m_bounce.loadFromFile("./assets/textures/bounce.png");
      m_sprite.loadFromFile("./assets/textures/spriteTexture.png");
      m_enemy.loadFromFile("./assets/textures/enemySpriteSheet.png");
  
      //Initialise picture variables
      m_picture.setSize(sf::Vector2f(8.f, 6.f));
      m_picture.setTexture(&amp;m_texture);
      m_picture.setPosition(0.f, 0.f);
      m_picture.setOrigin(4.f, 3.f);
  
      m_view.setCenter(0.f, 0.f);
      m_view.setSize(m_worldSize);
  
      m_pWorld = new b2World(mk_gravity);
  
      m_drawable_objects = {&amp;m_picture, m_character, m_simpEnemy1, m_ground, m_roof, m_plat1, m_bounce1, m_move1, m_coin, m_win};
  
      //create static blocks
      m_ground = new StaticBlock(m_pWorld, sf::Vector2f(0.f, 2.75f), sf::Vector2f(400.f, 0.5f), 0.f, &amp;m_floor, false);
      m_roof = new StaticBlock(m_pWorld, sf::Vector2f(0.f, -3.25f), sf::Vector2f(400.f, 0.5f), 0.f, &amp;m_floor, false);
      m_plat1 = new StaticBlock(m_pWorld, sf::Vector2f(3.f, 1.5f), sf::Vector2f(4.f, 0.5f), 0.f, &amp;m_floor, false);
      m_bounce1 = new StaticBlock(m_pWorld, sf::Vector2f(7.f, 1.5f), sf::Vector2f(2.f, 0.5f), 0.f, &amp;m_bounce, true);
  
      //create kinematic blocks
      m_move1 = new KinematicBlock(m_pWorld, sf::Vector2f(0.f, 0.25f), 1.f, sf::Vector2f(5.f, 0.5f), 0.f, &amp;m_floor);
  
      //create collectibles
      //m_coins = {m_coin};
      m_coin = new Collectible(m_pWorld, sf::Vector2f(2.f, 0.85f), sf::Vector2f(0.3f, 0.3f), 0.f, &amp;m_collect);
      //m_coin2 = new Collectible(m_pWorld, sf::Vector2f(2.f, 0.85f), sf::Vector2f(0.3f, 0.3f), 0.f, &amp;m_collect);
  
      //create character
      m_character = new Character(m_pWorld, sf::Vector2f(0.f, 2.25f), sf::Vector2f(0.25f, 0.5f), 0.f, &amp;m_sprite);
  
      //create enemies
      m_simpEnemy1 = new SimpleEnemy(m_pWorld, sf::Vector2f(4.f, 2.325f), 3.f, sf::Vector2f(0.75f, 0.375f), 0.f, &amp;m_enemy, sf::IntRect(0,17,41,14));
  
      //create winner pole
      m_win = new WinnerPole(m_pWorld, sf::Vector2f(15.f, 2.25f), sf::Vector2f(1.f, 0.5f), 0.f, &amp;m_bed);
  
      //set contact listener
      m_pWorld-&gt;SetContactListener(&amp;m_listener);
  }
  
  Game::~Game()
  {
      // Clean up all pointers
      delete m_pWorld;
      m_pWorld = nullptr;
  }
  
  void Game::update(float timestep)
  {
      // Update the world
      m_pWorld-&gt;Step(timestep, mk_iVelIterations, mk_iVelIterations);
      m_picture.setPosition(m_character-&gt;getPosition().x, 0.f);
      m_view.setCenter(m_character-&gt;getPosition().x, m_view.getCenter().y);
  
      // Update each dyanmic element - effectively update render information
      m_character-&gt;update();
      m_simpEnemy1-&gt;update();
      m_move1-&gt;update();
      m_coin-&gt;update();
  }
  
  void Game::draw(sf::RenderTarget &amp;target, sf::RenderStates states) const
  {
      // Set the view
      target.setView(m_view);
  
      // Draw everything
      for (auto * drawable : m_drawable_objects) 
      {
          target.draw(*drawable);
      }
  }
  </code></pre>