Drawing 'snake style' moving line - update not working

So, I wanted a line, that is moving in one direction (up and left - but because screen is not infinite there will be background moving back instead of line forward).
So, I have my sprites sorted in a vector crta like this:

 //in game.cpp/init    
//smer --> direction crta --> line,, zasilnoozadje-->background(I am not english)
    for(int a = 0; a < 15; a++){
    		cocos2d::Sprite* kvadrat = Sprite::create("kvadrat2.png");
    		if(a == 0){
    			kvadrat->setPosition(Vec2(origin.x, origin.y));
    			//smer = kvadrat->getContentSize().width/2;//desno, za levo *(-1)
    		}
    		else kvadrat->setPosition(Vec2(crta[a-1]->getPosition().x + smer, crta[a-1]->getPosition().y + smer));
    		this->addChild(kvadrat, 1);
    		crta.push_back(kvadrat);
    		
    	}

And it makes the line I want. (it goes from left down corner in right-up direction.
So I now want to make moving effect --> the line is mooving right. Is easy – just move every crta[i]to right in void Game::update(float delta){

But thats not what I wanted. Because I will soon ad a code, that line will chage direction when you will tap the screen. So lets say you tap the scren once since begining. Line would look like this:

\                                                     
  \                                                    
   \                                                    
    /                   
  /                                                         
 /    
  and next frame like this:                                            
\                                                     
  \                                                    
    \                                                    
      \                
      /                                                         
     /         

Very simmilar to classic snake game, it just have only 2 directions.
So I thing best mechanish would be, that we move upper sprite (crta[last] ) to right or left, based of the direction.
That works fine. But than I don’t want to do the same with other sprites. I wanted line to have more corners if needed.
Let it be n = last, and i = 0
So i thought , the best mechanism will be, that I go from crta[i] to crta [n-1], and make every sprite.y equal to sprite[i+1]. So the first code was sth like that:
I learn about update loop form this page

    void Game::update(float delta){
	//background works fine
	for(int i = 0; i < 15; i++){
		if(i = 14){//if its the last one
			auto position = crta[i]->getPosition();
			position.x += smer * delta;
			crta[i]->setPosition(position);
		}
		else {
			crta[i]->setPosition(Vec2(crta[i+1]->getPositionX(), crta[i]->getPositionY());
		}
}

But it didn’t work. It was youst wierd. - just one sprite mooving. I thougt there is sth worng using setposition so I do it like that.

    void Game::update(float delta){
	//background work fine
	int i = 0;
	auto moveTo = MoveTo::create(0.24, Vec2(crta[i+1]->getPositionX(), crta[i]->getPositionY()));
	for(i = 0; i < 15; i++){
		if(i = 14){
			auto position = crta[i]->getPosition();
			position.x += smer * delta;
			crta[i]->setPosition(position);
		}
		else {
			crta[i]->runAction(moveTo);
		}
		
	}
}

I think, I am missing something about that update think or something.
So has anybody have idea hov to do that? I will be happy to hear it.
Thankx for help!

I think you should create array of sprites like that:
.h file
Sprite* mySpriteArray[15];

.cpp file
for (int i=0,i<15,++1)
mySpriteArray[i] = Sprite::create(“kvadrat2.png”);

Why? Way woulkd it be better?
ANd do I need some new headers includet for array ? Cocos2s Array or wath?

DRAWING a line works fine. MOVING a line makes problems.

  1. keep track of the direction & position of the current snake head
  2. calculate the new/projected direction & position of the current snake head
  3. move the snake tail to the head’s projected position & direction then make it the current head

Just repeat the process, say every 1 second, your line should move like a snake.

Yes, but I wat my line to move only left and right, and the effect will be it looks luike it is “moving up”… (background muving back…).
SO with your alghoritm, I should move every sprite back after it… It is not so god mechanism. I already have ter good one. I just don’t know whats wrong with update void.

If there is anybody asking themself about this question solution using update would be making int directions[number of sprites in line] (Before I had just one direction…
And the loop in void update(float delta) woud look like this:

	for(int i = 0; i < 15; i++){		
	if(i < 14){
		auto position = crta[i]->getPosition();
		position.x += hitrost * smeri[i] * delta;
		smeri[i] = smeri[i+1];
		crta[i]->setPosition(position);
	}
	else{
		auto position = crta[i]->getPosition();
		position.x += hitrost * smeri[i] * delta;
		crta[i]->setPosition(position);
	}
}