1

所以我在这里有这段代码:

void Star::createStar(){
sf::CircleShape star1(r,50);
star1.setPosition(x,y);
sf::Texture* t = CreateTexture(256,256);
star1.setTexture(t,false);
star=star1;
std::cout << "Done!"<<std::endl;
}
void Star::update(){
star.setOrigin(x-(.5*r),y-(.5*r));

star.rotate(0.01);
}

我希望星星围绕它的中心旋转,但我可能做错了计算,但它似乎围绕着同一点旋转,即使我没有声明中心也是如此。

编辑:: 我修复了 star.setOrigin() 应该有参数 r,r!

4

1 回答 1

2

这是正确的代码

void Star::createStar(){
sf::CircleShape star1(r,50);
star1.setPosition(x,y);
sf::Texture* t = CreateTexture(256,256);
star1.setTexture(t,false);
star=star1;
std::cout << "Done!"<<std::endl;
}
void Star::update(){
//star.setOrigin(x-(.5*r),y-(.5*r));
//no need to set origin
star.rotate(0.01);
}
于 2014-05-29T19:55:38.813 回答