0
我正在製作一款射擊遊戲,玩家可以在鼠標上進行拍攝,所以我拿到槍指向鼠標,但我無法弄清楚如何在圖像左轉後正確翻轉圖像。我的意思是,我確實翻轉了圖像,但沒有對齊。我不確定如何解釋它,這是我的代碼。如何翻轉圖像並同時將槍指向鼠標? (SFML)
void PortalGun::update(Vector2i mPos) {
float pi = 3.14159265359;
float rotation = atan2(sprite.getGlobalBounds().top - mPos.y,sprite.getGlobalBounds().left - mPos.x) * 180/pi;
int x = player->sprite.getGlobalBounds().left + 16;
int y = player->sprite.getGlobalBounds().top;
if (rotation > -90 && rotation < 90) {
player->dir = -1;
sprite.setTextureRect(IntRect(0, 32, 64, -32));
} else {
player->dir = 1;
sprite.setTextureRect(IntRect(0, 0, 64, 32));
}
sprite.setPosition(x, y + 15);
sprite.setRotation(rotation + 170);
}
當鼠標到噴槍的左側,它翻轉圖像,而是保持向上旋轉,以便鼠標20個ISH像素高。旋轉時我不能只改變位置,所以我該怎麼辦?對不起,聽起來有點神祕,有點難以解釋。
是否有任何具體的原因你使用sf :: Sprite :: getGlobalBounds()'? – Mario