title: How to Move All Sprites At Once: Cocos2dx v3 C++
body: <p>I'm attempting to make a Space Invaders clone. In doing so I'm having a difficult time grouping the invaders together so that they move at the same time.This is due to both CCLayer and CCNode being deprecated in v3.1 in cocos2dx. I saved my sprites to a vector that I can iterate over but when I attempt to move them only move one at a time. I need to group them together so I can move them all at once. </p>
  
  <pre><code>void Gameplay::moveInvaders(){
      auto moveLeft = MoveBy::create(2, Vec2(-1, 0));
      auto moveRight = MoveBy::create(2, Vec2(1, 0));
      auto moveDown = MoveBy::create(2, Vec2(0, 1));
      auto stay = MoveBy::create(20, Vec2(0,0));
  
      // create a sequence with the actions and callbacks
      auto seq = Sequence::create(moveLeft, stay, moveRight, stay, moveDown, stay, nullptr);
  
      for (int i = 0; i &lt; invaders.size(); i++) {
          invaders.at(i)-&gt;runAction(seq);
      }
  </code></pre>
  
  <p>Update: I ended up figuring out the issue. Instead of trying to use the sequence I ended up scripting the movements with some control logic and the system timer.</p>
  
  <p>Add this to your init() function:
          <code>this-&gt;schedule(schedule_selector(Gameplay::moveInvaders), 1.0);</code></p>
  
  <p>Of the form: </p>
  
  <pre><code>this-&gt;schedule(schedule_selector(&lt;Class_Name&gt;::&lt;function_To_call&gt;), &lt;number_of_frames_to_run&gt;);
  </code></pre>
  
  <p>Then decide what you want to do in your function that will be called that often. I used a couple of boolean and int values to keep a counter. That way I could control the direction the invaders would move.</p>
  
  <p>Hopefully this helps somebody else! I couldn't find what I needed to know because most of the tutorials for cocos2dx were in Objective-C or Javascript.</p>