Variables for creating a 5x5 box I have to create a 5x5 box using the images, and my first solution was to create 25 variables and print them, which is very inefficient. How can I optimize this? This utilizes cocos2d-x.

auto cudrado0 = Sprite::create("images.png");
cudrado0-&gt;setPosition(Vec2(200, 200));
cudrado0-&gt;setScale(0.5);
this-&gt;addChild(cudrado0, 0);


auto cudrado1 = Sprite::create("images.png");
cudrado1-&gt;setPosition(Vec2(200, 275));
cudrado1-&gt;setScale(0.5);
this-&gt;addChild(cudrado1, 0);

 auto cudrado2 = Sprite::create("images.png");
cudrado2-&gt;setPosition(Vec2(200, 350));
cudrado2-&gt;setScale(0.5);
this-&gt;addChild(cudrado2, 0);

auto cudrado3 = Sprite::create("images.png");
cudrado3-&gt;setPosition(Vec2(200, 425));
cudrado3-&gt;setScale(0.5);
this-&gt;addChild(cudrado3, 0);

auto cudrado4 = Sprite::create("images.png");
cudrado4-&gt;setPosition(Vec2(200, 500));
cudrado4-&gt;setScale(0.5);
this-&gt;addChild(cudrado4, 0);

 auto cudrado5 = Sprite::create("images.png");
cudrado5-&gt;setPosition(Vec2(275, 200));
cudrado5-&gt;setScale(0.5);
this-&gt;addChild(cudrado5, 0);

auto cudrado6 = Sprite::create("images.png");
cudrado6-&gt;setPosition(Vec2(350, 200));
cudrado6-&gt;setScale(0.5);
this-&gt;addChild(cudrado6, 0);

 auto cudrado7 = Sprite::create("images.png");
cudrado7-&gt;setPosition(Vec2(425, 200));
cudrado7-&gt;setScale(0.5);
this-&gt;addChild(cudrado7, 0);

auto cudrado8 = Sprite::create("images.png");
cudrado8-&gt;setPosition(Vec2(500, 200));
cudrado8-&gt;setScale(0.5);
this-&gt;addChild(cudrado8, 0);

  auto cudrado9 = Sprite::create("images.png");
cudrado9-&gt;setPosition(Vec2(275, 275));
cudrado9-&gt;setScale(0.5);
this-&gt;addChild(cudrado9, 0);

 auto cudrado10 = Sprite::create("images.png");
cudrado10-&gt;setPosition(Vec2(350, 275));
cudrado10-&gt;setScale(0.5);
this-&gt;addChild(cudrado10, 0);

auto cudrado11 = Sprite::create("images.png");
cudrado11-&gt;setPosition(Vec2(425, 275));
cudrado11-&gt;setScale(0.5);
this-&gt;addChild(cudrado11, 0);

auto cudrado12 = Sprite::create("images.png");
cudrado12-&gt;setPosition(Vec2(500, 275));
cudrado12-&gt;setScale(0.5);
this-&gt;addChild(cudrado12, 0);

auto cudrado13 = Sprite::create("images.png");
cudrado13-&gt;setPosition(Vec2(275, 350));
cudrado13-&gt;setScale(0.5);
this-&gt;addChild(cudrado13, 0);

auto cudrado14 = Sprite::create("images.png");
cudrado14-&gt;setPosition(Vec2(350, 350));
cudrado14-&gt;setScale(0.5);
this-&gt;addChild(cudrado14, 0);

auto cudrado15 = Sprite::create("images.png");
cudrado15-&gt;setPosition(Vec2(425, 350));
cudrado15-&gt;setScale(0.5);
this-&gt;addChild(cudrado15, 0);

auto cudrado16 = Sprite::create("images.png");
cudrado16-&gt;setPosition(Vec2(500, 350));
cudrado16-&gt;setScale(0.5);
this-&gt;addChild(cudrado16, 0);

auto cudrado17 = Sprite::create("images.png");
cudrado17-&gt;setPosition(Vec2(275, 425));
cudrado17-&gt;setScale(0.5);
this-&gt;addChild(cudrado17, 0);

auto cudrado18 = Sprite::create("images.png");
cudrado18-&gt;setPosition(Vec2(350, 425));
cudrado18-&gt;setScale(0.5);
this-&gt;addChild(cudrado18, 0);

auto cudrado19 = Sprite::create("images.png");
cudrado19-&gt;setPosition(Vec2(425, 425));
cudrado19-&gt;setScale(0.5);
this-&gt;addChild(cudrado19, 0);

auto cudrado20 = Sprite::create("images.png");
cudrado20-&gt;setPosition(Vec2(500, 425));
cudrado20-&gt;setScale(0.5);
this-&gt;addChild(cudrado20, 0);

auto cudrado21 = Sprite::create("images.png");
cudrado21-&gt;setPosition(Vec2(275, 500));
cudrado21-&gt;setScale(0.5);
this-&gt;addChild(cudrado21, 0);

auto cudrado22 = Sprite::create("images.png");
cudrado22-&gt;setPosition(Vec2(350, 500));
cudrado22-&gt;setScale(0.5);
this-&gt;addChild(cudrado22, 0);

auto cudrado23 = Sprite::create("images.png");
cudrado23-&gt;setPosition(Vec2(425, 500));
cudrado23-&gt;setScale(0.5);
this-&gt;addChild(cudrado23, 0);

auto cudrado24 = Sprite::create("images.png");
cudrado24-&gt;setPosition(Vec2(500, 500));
cudrado24-&gt;setScale(0.5);
this-&gt;addChild(cudrado24, 0);
If you have to print a 5x5 box with the a different image or the same you could do something like this. It loops though all the positions that you need and assigns it to a new sprite created. It is more maintaineable, cleaner and easy to read than declaring 25 variables, and it has fewer lines of code.

// Construct the vector with the specified size.
Vec2 size(5, 5);
std::vector&lt;Vec2&gt; positions(size.x * size.y);

// Push back desired positions (you could use C++11 initializer lists or a loop).
// Positions needs to be declared in the same order as the sprites will be
// added with "this-&gt;addChild".
positions.push_back(position);
...

float scale(0.5);

// Loop trought the vector and assign values
for (int i = 0; i &lt; size.x * size.y; i++) {
    auto sprite = Sprite::create("theimageyouneed.png");
    sprite-&gt;setPosition(positions[i]);
    sprite-&gt;setScale(scale);
    this-&gt;addChild(sprite, 0);
}