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

Author Topic: No Errors, but Sprite wont draw?  (Read 1789 times)

0 Members and 1 Guest are viewing this topic.

JTeck

  • Newbie
  • *
  • Posts: 35
    • View Profile
No Errors, but Sprite wont draw?
« on: May 15, 2014, 02:36:42 am »
Hi, I've been having troubles drawing my sprite, in my Player class where I'm loading the images, I get no errors when loading the images for the texture, but when I goto run the application, the sprite isn't showing, I have other objects being drawn as well, I have the player being drawn last after everything else, but still down do anything?

Any Ideas?

Drawing the Characters Sprite (This is being called after a statement returns true)
void Lester::PlayerSetup()
{
    Player player = *new Player();
    sf::Sprite p_sprite(player.p_sprite);
    p_sprite.setPosition(200, 200);
    p_sprite.setTexture(player.tp_sprite);

    window->draw(p_sprite);
}
 
Player Declarations for sprite image loading
void Player::texture()
{
    //tp_down_sprite->loadFromFile("data/assets/player/down_char.png");
    //tp_left_sprite->loadFromFile("data/assets/player/left_char.png");
    //tp_right_sprite->loadFromFile("data/assets/player/right_char.png");
    //tp_up_sprite->loadFromFile("data/assets/player/up_char.png");

    if (!tp_sprite.loadFromFile("data/assets/player/up_char.png")){ std::cout << "Unable to load Player Sprites! Please report this Error!"; }
    else{ std::cout << "Player Sprite was Loaded Correctly"; }
    p_sprite.setTexture(tp_sprite);
}

Cheers.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: No Errors, but Sprite wont draw?
« Reply #1 on: May 15, 2014, 07:51:23 am »
You should not be drawing the sprite in your player's constructor/init method.  draw() calls should only happen in between the clear() and display() calls of your main loop.  If PlayerSetup() is being called every frame, then only draw() should be in there.

Quote
This is being called after a statement returns true
If you feel the need to describe more of your code, that implies you haven't shown us enough of the code to begin with.  If you need more help be sure to post a *complete* and minimal example.

JTeck

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: No Errors, but Sprite wont draw?
« Reply #2 on: May 15, 2014, 01:01:48 pm »
You should not be drawing the sprite in your player's constructor/init method.  draw() calls should only happen in between the clear() and display() calls of your main loop.  If PlayerSetup() is being called every frame, then only draw() should be in there.

Quote
This is being called after a statement returns true
If you feel the need to describe more of your code, that implies you haven't shown us enough of the code to begin with.  If you need more help be sure to post a *complete* and minimal example.

This the entire cpp file for drawing onto screen. http://pastebin.com/8j59jtvF

I've added the draw() and display() calls in the main loop, and set it so its just draw() in PlayerSetup(), but it still isn't showing?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: No Errors, but Sprite wont draw?
« Reply #3 on: May 15, 2014, 01:07:19 pm »
This the entire cpp file
Please read this
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: