Firstly i am so sorry for my so bad english. I am new on game developing and i try learn. I try writing a snake game, but have 2 problems for now. My first problem snake dont stable while on move and i when change the rotation,then the all body parts changing rotation but i want the part of body come to on head starting point rotation.
Some images on my problems;
My moving method;
void GameScene::snakeMove(float x,float y){
x=snakeHead->getPositionX();
y=snakeHead->getPositionY();
if(snakeHead->getRotation()==90 || snakeHead->getRotation()==270 ){
auto move = MoveBy::create(0.1f,
Vec2(-cos((snakeHead->getRotation())*M_PI / 180.0f)snakeHead->getContentSize().width/4SNAKE_BODY_SPACE,
-sin((snakeHead->getRotation())*M_PI / 180.0f)snakeHead->getContentSize().height/4SNAKE_BODY_SPACE));
snakeHead->runAction(move);
}
else {
auto move = MoveBy::create(0.1f,
Vec2(-cos((snakeHead->getRotation()+180)*M_PI / 180.0f)snakeHead->getContentSize().width/4SNAKE_BODY_SPACE,
-sin((snakeHead->getRotation()+180)*M_PI / 180.0f)snakeHead->getContentSize().height/4SNAKE_BODY_SPACE));
snakeHead->runAction(move);
}if(snakeHead->getPositionX()>(origin.x+visibleSize.width) ||snakeHead->getPositionX()<origin.x ||snakeHead->getPositionY()>(origin.y+visibleSize.height) ||snakeHead->getPositionY()<origin.y) Director::getInstance()->pushScene(TransitionFade::create(0,GameScene::createScene())); for (int i = 1; i < snakeSize; i++){ auto move = MoveTo::create(0.1f, snakeBodyParts.at(i - 1)->getPosition()); snakeBodyParts.at(i)->runAction(move); /* if(snakeBodyParts.at(i)->getPositionX()==x && snakeBodyParts.at(i)->getPositionY()==y){ auto rotate = RotateTo::create(0.1f, snakeRotation); snakeBodyParts.at(i)->runAction(rotate); }*/ //I tried this for moving rotation but not working }
}