SFML community forums

Help => General => Topic started by: idontreallywolf on January 18, 2017, 10:03:07 pm

Title: can't place sprite on center
Post by: idontreallywolf on January 18, 2017, 10:03:07 pm
I have been trying to place this sprite on the center of the window by using the code below...
But the sprite is placed on TOP-LEFT corner of the window.
Spaceship::Spaceship(sf::RenderWindow& game_window){
    auto surface = sf::VideoMode::getDesktopMode();
    signed int ss_x = surface.width/2;
    signed int ss_y = surface.height/2;
   
    int ss_width = 128;
    int ss_height = 128;
    int ss_radius = ss_width/2;
   
   
}

void Spaceship::drawsprite(sf::RenderWindow& game_window){
    sf::Texture ship;
    if (!ship.loadFromFile(resourcePath() + "space-shuttle-64.png")) {
        return EXIT_FAILURE;
    }
    sf::Sprite ss_sprite(ship);
    ss_sprite.setPosition(ss_x,ss_y);
    game_window.draw(ss_sprite);
}
 
Title: Re: can't place sprite on center
Post by: idontreallywolf on January 18, 2017, 11:10:33 pm
PROBLEM SOLVED:

STACKOVERFLOW LINK (http://stackoverflow.com/questions/41729773/sfml-place-sprite-on-center)