Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: can't place sprite on center  (Read 751 times)

0 Members and 1 Guest are viewing this topic.

idontreallywolf

  • Newbie
  • *
  • Posts: 2
    • View Profile
can't place sprite on center
« 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);
}
 
« Last Edit: January 18, 2017, 10:05:17 pm by idontreallywolf »

idontreallywolf

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: can't place sprite on center
« Reply #1 on: January 18, 2017, 11:10:33 pm »
PROBLEM SOLVED:

STACKOVERFLOW LINK

 

anything