and the last one is update function in snake.cpp file
void Snake::update(){
{
auto _mp = snakeHead->getPosition();
auto _Mp = _mp.operator+(Vec2(BODY_INTERVAL * sind(snakeHead->getRotation()), BODY_INTERVAL * cosd(snakeHead->getRotation())));
snakeHead->setPosition(_Mp);
}
isMoving = true;
for (int i = 1; i < size; i++){
auto _mp = snakeBodyParts.at(i)->getPosition();
Vec2 vec(snakeBodyParts.at(i - 1)->getPosition().x, snakeBodyParts.at(i - 1)->getPosition().y);
auto _Mp = _mp.operator+(vec);
snakeBodyParts.at(i)->setPosition(_Mp);
}
}
My problem is when i run project snake not appeared. I don’t know how to fix.
I have a Snake class inherited Node class, this Snake node groups many sprites, those sprites are each part of a snake.I have a layer which is child of scene, and that layer is parent of Snake node, and yeah snake parts are child of Snake. I call function update of layer in function update of scene.cpp, then update function of layer calls update of snake. My function update of snake is to move snake from left to right.Everything is find until i run project , the snake does not appear. Can you guys help me out of this? Really appreciate
oh that’s my mistake when i add that scope, i get rid of it, and snake still does not appear. I added CCLOG() to check whether update function of snake is called, and the result is yes,that update function is called But i don’t know why the snake does not appear. Here the clue: when i do like this
auto _mp = snakeHead->getPosition();
//auto _Mp = _mp.operator+(Vec2(BODY_INTERVAL * sind(snakeHead->getRotation()), BODY_INTERVAL * cosd(snakeHead->getRotation())));
auto _Mp = _mp.operator+(Vec2(100,0));
snakeHead->setPosition(_Mp);
isMoving = true;
/*for (int i = 1; i < size; i++){
auto _mp = snakeBodyParts.at(i)->getPosition();
Vec2 vec(snakeBodyParts.at(i - 1)->getPosition().x, snakeBodyParts.at(i - 1)->getPosition().y);
auto _Mp = _mp.operator+(vec);
snakeBodyParts.at(i)->setPosition(_Mp);
}*/ // i comment to all of this
CCLOG("UPDATE");
and run project, snake body appears at the initial position but they don’t move . And when i do like this
/*auto _mp = snakeHead->getPosition();
auto _Mp = _mp.operator+(Vec2(BODY_INTERVAL * sind(snakeHead->getRotation()), BODY_INTERVAL * cosd(snakeHead->getRotation())));
auto _Mp = _mp.operator+(Vec2(100,0));
snakeHead->setPosition(_Mp);*/ // i comment all of this
isMoving = true;
for (int i = 1; i < size; i++){
auto _mp = snakeBodyParts.at(i)->getPosition();
Vec2 vec(snakeBodyParts.at(i - 1)->getPosition().x, snakeBodyParts.at(i - 1)->getPosition().y);
auto _Mp = _mp.operator+(vec);
snakeBodyParts.at(i)->setPosition(_Mp);
}
CCLOG("UPDATE");
and run project snake head appears at initial position and does not move . And snake body does not appear.
Any clue. Thanks for spending your time
why not put log statements in your for loop and output position and other necessary debugging info.
Better would be to add breakpoints and just debug it while it is running and watch the console and the stack.
I dont have time to step through each step of your code distributed among multiple posts.